aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
authorJoris2016-08-08 20:58:17 +0200
committerJoris2016-08-08 20:58:17 +0200
commit8816cf758119a6a2073e561c8df297a833630986 (patch)
tree20e63f3c0de15945b818a6d7a78359f9134b5e82 /src/server/Controller
parentb54d8e45fc8784d8fa6eaa03f58536b7a19cf70b (diff)
Show incomes in a table and update like payments are updated
Diffstat (limited to 'src/server/Controller')
-rw-r--r--src/server/Controller/Income.hs32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/server/Controller/Income.hs b/src/server/Controller/Income.hs
index fa575c5..ff3e75d 100644
--- a/src/server/Controller/Income.hs
+++ b/src/server/Controller/Income.hs
@@ -1,9 +1,9 @@
{-# LANGUAGE OverloadedStrings #-}
module Controller.Income
- ( getIncomes
- , createIncome
- , deleteOwnIncome
+ ( create
+ , editOwn
+ , deleteOwn
) where
import Web.Scotty
@@ -25,23 +25,27 @@ import Model.Database
import qualified Model.Income as Income
import qualified Model.Message.Key as Key
import qualified Model.Json.CreateIncome as Json
+import qualified Model.Json.EditIncome as Json
-getIncomes :: ActionM ()
-getIncomes =
- Secure.loggedAction (\_ ->
- (liftIO $ map Income.getJsonIncome <$> runDb Income.getIncomes) >>= json
+create :: Json.CreateIncome -> ActionM ()
+create (Json.CreateIncome date amount) =
+ Secure.loggedAction (\user ->
+ (liftIO . runDb $ Income.create (entityKey user) date amount) >>= jsonId
)
-createIncome :: Json.CreateIncome -> ActionM ()
-createIncome (Json.CreateIncome date amount) =
- Secure.loggedAction (\user ->
- (liftIO . runDb $ Income.createIncome (entityKey user) date amount) >>= jsonId
+editOwn :: Json.EditIncome -> ActionM ()
+editOwn (Json.EditIncome incomeId date amount) =
+ Secure.loggedAction (\user -> do
+ updated <- liftIO . runDb $ Income.editOwn (entityKey user) incomeId date amount
+ if updated
+ then status ok200
+ else status badRequest400
)
-deleteOwnIncome :: Text -> ActionM ()
-deleteOwnIncome incomeId =
+deleteOwn :: Text -> ActionM ()
+deleteOwn incomeId =
Secure.loggedAction (\user -> do
- deleted <- liftIO . runDb $ Income.deleteOwnIncome user (textToKey incomeId)
+ deleted <- liftIO . runDb $ Income.deleteOwn user (textToKey incomeId)
if deleted
then
status ok200