module Model.Income ( getIncome , getFirstIncome , getIncomes , setIncome ) where import Data.Time.Clock (getCurrentTime) import Control.Monad.IO.Class (liftIO) import Database.Persist import Model.Database getIncome :: UserId -> Persist (Maybe Income) getIncome userId = fmap entityVal <$> selectFirst [IncomeUserId ==. userId] [Desc IncomeCreation] getIncomes :: Persist [Income] getIncomes = map entityVal <$> selectList [] [] getFirstIncome :: UserId -> Persist (Maybe Income) getFirstIncome userId = fmap entityVal <$> selectFirst [IncomeUserId ==. userId] [Asc IncomeCreation] setIncome :: UserId -> Int -> Persist IncomeId setIncome userId amount = do now <- liftIO getCurrentTime insert (Income userId now amount)