aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Controller')
-rw-r--r--src/server/Controller/Income.hs10
-rw-r--r--src/server/Controller/Payment.hs34
2 files changed, 21 insertions, 23 deletions
diff --git a/src/server/Controller/Income.hs b/src/server/Controller/Income.hs
index 70e40ce..fa575c5 100644
--- a/src/server/Controller/Income.hs
+++ b/src/server/Controller/Income.hs
@@ -2,7 +2,7 @@
module Controller.Income
( getIncomes
- , addIncome
+ , createIncome
, deleteOwnIncome
) where
@@ -24,7 +24,7 @@ import Json (jsonId)
import Model.Database
import qualified Model.Income as Income
import qualified Model.Message.Key as Key
-import qualified Model.Json.AddIncome as Json
+import qualified Model.Json.CreateIncome as Json
getIncomes :: ActionM ()
getIncomes =
@@ -32,10 +32,10 @@ getIncomes =
(liftIO $ map Income.getJsonIncome <$> runDb Income.getIncomes) >>= json
)
-addIncome :: Json.AddIncome -> ActionM ()
-addIncome (Json.AddIncome date amount) =
+createIncome :: Json.CreateIncome -> ActionM ()
+createIncome (Json.CreateIncome date amount) =
Secure.loggedAction (\user ->
- (liftIO . runDb $ Income.addIncome (entityKey user) date amount) >>= jsonId
+ (liftIO . runDb $ Income.createIncome (entityKey user) date amount) >>= jsonId
)
deleteOwnIncome :: Text -> ActionM ()
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs
index 294e4c4..55edea5 100644
--- a/src/server/Controller/Payment.hs
+++ b/src/server/Controller/Payment.hs
@@ -1,9 +1,9 @@
{-# LANGUAGE OverloadedStrings #-}
module Controller.Payment
- ( getPayments
- , createPayment
- , deleteOwnPayment
+ ( list
+ , create
+ , deleteOwn
) where
import Web.Scotty
@@ -16,34 +16,32 @@ import Control.Monad.IO.Class (liftIO)
import Data.Text (Text)
import qualified Data.Text.Lazy as TL
-import qualified Data.Aeson.Types as Json
import qualified Secure
-import Json (jsonObject)
+import Json (jsonId)
import Model.Database
-import qualified Model.Payment as P
-import Model.Frequency
+import qualified Model.Payment as Payment
import Model.Message.Key (Key(PaymentNotDeleted))
+import qualified Model.Json.CreatePayment as Json
-getPayments :: ActionM ()
-getPayments =
+list :: ActionM ()
+list =
Secure.loggedAction (\_ -> do
- (liftIO $ runDb P.getPayments) >>= json
+ (liftIO $ runDb Payment.list) >>= json
)
-createPayment :: Text -> Int -> Frequency -> ActionM ()
-createPayment name cost frequency =
- Secure.loggedAction (\user -> do
- paymentId <- liftIO . runDb $ P.createPayment (entityKey user) name cost frequency
- jsonObject [("id", Json.Number . fromIntegral . keyToInt64 $ paymentId)]
+create :: Json.CreatePayment -> ActionM ()
+create (Json.CreatePayment date name cost frequency) =
+ Secure.loggedAction (\user ->
+ (liftIO . runDb $ Payment.create (entityKey user) date name cost frequency) >>= jsonId
)
-deleteOwnPayment :: Text -> ActionM ()
-deleteOwnPayment paymentId =
+deleteOwn :: Text -> ActionM ()
+deleteOwn paymentId =
Secure.loggedAction (\user -> do
- deleted <- liftIO . runDb $ P.deleteOwnPayment user (textToKey paymentId)
+ deleted <- liftIO . runDb $ Payment.deleteOwn user (textToKey paymentId)
if deleted
then
status ok200