aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model
diff options
context:
space:
mode:
authorJoris2015-09-13 12:04:52 +0200
committerJoris2015-09-13 12:04:52 +0200
commit5babf01323bcb62a9880593165af70732f22751b (patch)
tree716373ce6f3ebeaa0bb532b30d2a3b65d894d128 /src/server/Model
parenta94813019b146d75f7556d10e8d0dfd50586f54d (diff)
Adding income database table with a getter and a setter
Diffstat (limited to 'src/server/Model')
-rw-r--r--src/server/Model/Database.hs4
-rw-r--r--src/server/Model/Income.hs21
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)