diff options
author | Joris | 2016-06-26 12:31:24 +0200 |
---|---|---|
committer | Joris | 2016-06-26 12:31:24 +0200 |
commit | 9ec84e3a20c767f6525639f58cd22715e302b88d (patch) | |
tree | a080552859180707472c1a289080857c0a54fc06 /src/server/Controller | |
parent | 5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff) |
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/server/Controller')
-rw-r--r-- | src/server/Controller/Income.hs | 10 | ||||
-rw-r--r-- | src/server/Controller/Payment.hs | 34 |
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 |