diff options
Diffstat (limited to 'src/server/Model')
-rw-r--r-- | src/server/Model/Database.hs | 4 | ||||
-rw-r--r-- | src/server/Model/Income.hs | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/server/Model/Database.hs b/src/server/Model/Database.hs index 0bbc353..c88322f 100644 --- a/src/server/Model/Database.hs +++ b/src/server/Model/Database.hs @@ -52,6 +52,10 @@ Job lastExecution UTCTime Maybe UniqJobName kind deriving Show +Income + userId UserId + creation UTCTime + amount Int |] type Persist a = SqlPersistT (ResourceT (NoLoggingT IO)) a diff --git a/src/server/Model/Income.hs b/src/server/Model/Income.hs new file mode 100644 index 0000000..edf1c92 --- /dev/null +++ b/src/server/Model/Income.hs @@ -0,0 +1,21 @@ +module Model.Income + ( getIncome + , 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] + +setIncome :: UserId -> Int -> Persist IncomeId +setIncome userId amount = do + now <- liftIO getCurrentTime + insert (Income userId now amount) |