From 5babf01323bcb62a9880593165af70732f22751b Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Sep 2015 12:04:52 +0200 Subject: Adding income database table with a getter and a setter --- src/server/Model/Database.hs | 4 ++++ src/server/Model/Income.hs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/server/Model/Income.hs (limited to 'src/server/Model') 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) -- cgit v1.2.3