diff options
Diffstat (limited to 'src/server/Controller/Payment.hs')
-rw-r--r-- | src/server/Controller/Payment.hs | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs index 85e2a87..02c8a8e 100644 --- a/src/server/Controller/Payment.hs +++ b/src/server/Controller/Payment.hs @@ -1,12 +1,12 @@ {-# LANGUAGE OverloadedStrings #-} module Controller.Payment - ( getPaymentsAction - , getMonthlyPaymentsAction - , createPaymentAction - , deletePaymentAction - , getTotalPaymentsAction - , getPaymentsCountAction + ( getPayments + , getMonthlyPayments + , createPayment + , deletePayment + , getTotalPayments + , getPaymentsCount ) where import Web.Scotty @@ -22,40 +22,39 @@ import qualified Data.Aeson.Types as Json import qualified Secure +import Json (jsonObject) + import Model.Database -import Model.Payment +import qualified Model.Payment as P import Model.Frequency import Model.Json.Number import qualified Model.Json.PaymentId as JP import Model.Message import Model.Message.Key (Key(PaymentNotDeleted)) - -import Json (jsonObject) - -getPaymentsAction :: Int -> Int -> ActionM () -getPaymentsAction page perPage = +getPayments :: Int -> Int -> ActionM () +getPayments page perPage = Secure.loggedAction (\_ -> do - (liftIO $ runDb (getPunctualPayments page perPage)) >>= json + (liftIO $ runDb (P.getPunctualPayments page perPage)) >>= json ) -getMonthlyPaymentsAction :: ActionM () -getMonthlyPaymentsAction = +getMonthlyPayments :: ActionM () +getMonthlyPayments = Secure.loggedAction (\user -> do - (liftIO $ runDb (getUserMonthlyPayments (entityKey user))) >>= json + (liftIO $ runDb (P.getUserMonthlyPayments (entityKey user))) >>= json ) -createPaymentAction :: Text -> Int -> Frequency -> ActionM () -createPaymentAction name cost frequency = +createPayment :: Text -> Int -> Frequency -> ActionM () +createPayment name cost frequency = Secure.loggedAction (\user -> do - paymentId <- liftIO . runDb $ createPayment (entityKey user) name cost frequency + paymentId <- liftIO . runDb $ P.createPayment (entityKey user) name cost frequency json (JP.PaymentId paymentId) ) -deletePaymentAction :: Text -> ActionM () -deletePaymentAction paymentId = +deletePayment :: Text -> ActionM () +deletePayment paymentId = Secure.loggedAction (\user -> do - deleted <- liftIO . runDb $ deleteOwnPayment user (textToKey paymentId) + deleted <- liftIO . runDb $ P.deleteOwnPayment user (textToKey paymentId) if deleted then status ok200 @@ -64,14 +63,14 @@ deletePaymentAction paymentId = jsonObject [("error", Json.String $ getMessage PaymentNotDeleted)] ) -getTotalPaymentsAction :: ActionM () -getTotalPaymentsAction = +getTotalPayments :: ActionM () +getTotalPayments = Secure.loggedAction (\_ -> do - (liftIO . runDb $ getTotalPayments) >>= json + (liftIO . runDb $ P.getTotalPayments) >>= json ) -getPaymentsCountAction :: ActionM () -getPaymentsCountAction = +getPaymentsCount :: ActionM () +getPaymentsCount = Secure.loggedAction (\_ -> do - Number <$> (liftIO . runDb $ getPaymentsCount) >>= json + Number <$> (liftIO . runDb $ P.getPaymentsCount) >>= json ) |