aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
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