aboutsummaryrefslogtreecommitdiff
path: root/server/src/Controller
diff options
context:
space:
mode:
authorJoris2018-10-28 17:57:58 +0100
committerJoris2018-10-28 17:57:58 +0100
commit40b4994797a797b1fa86cafda789a5c488730c6d (patch)
treead195b31fa442821b9de8f99364e254f0f41935f /server/src/Controller
parentdf83b634006c699cfa1e921bf74ce951a906a62f (diff)
Delete payment
Diffstat (limited to 'server/src/Controller')
-rw-r--r--server/src/Controller/Payment.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/server/src/Controller/Payment.hs b/server/src/Controller/Payment.hs
index e1936f0..4edbf6a 100644
--- a/server/src/Controller/Payment.hs
+++ b/server/src/Controller/Payment.hs
@@ -18,6 +18,7 @@ import qualified Model.Query as Query
import qualified Persistence.Payment as PaymentPersistence
import qualified Persistence.PaymentCategory as PaymentCategoryPersistence
import qualified Secure
+import qualified Validation.CreatePayment as CreatePaymentValidation
list :: ActionM ()
list =
@@ -26,12 +27,18 @@ list =
)
create :: CreatePayment -> ActionM ()
-create (CreatePayment name cost date category frequency) =
+create createPayment@(CreatePayment name cost date category frequency) =
Secure.loggedAction (\user ->
- (liftIO . Query.run $ do
- PaymentCategoryPersistence.save name category
- PaymentPersistence.create (_user_id user) name cost date frequency
- ) >>= Json.jsonId
+ case CreatePaymentValidation.validate createPayment of
+ Nothing ->
+ (liftIO . Query.run $ do
+ PaymentCategoryPersistence.save name category
+ PaymentPersistence.create (_user_id user) name cost date frequency
+ ) >>= Json.jsonId
+ Just validationError ->
+ do
+ status Status.badRequest400
+ json validationError
)
editOwn :: EditPayment -> ActionM ()