blob: 70b91493d045310dd04ff75f057288e797014243 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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)
|