diff options
Diffstat (limited to 'src/server/Controller/Payment.hs')
-rw-r--r-- | src/server/Controller/Payment.hs | 34 |
1 files changed, 16 insertions, 18 deletions
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 |