aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Controller')
-rw-r--r--src/server/Controller/Payment.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs
index 141aed0..cbd342a 100644
--- a/src/server/Controller/Payment.hs
+++ b/src/server/Controller/Payment.hs
@@ -1,10 +1,13 @@
module Controller.Payment
( getPaymentsAction
, createPaymentAction
+ , deletePaymentAction
) where
import Web.Scotty
+import Network.HTTP.Types.Status (ok200, badRequest400)
+
import Database.Persist
import Control.Monad.IO.Class (liftIO)
@@ -16,6 +19,8 @@ import qualified Secure
import Model.Database
import Model.Payment
import Model.Json.Message
+import Model.Message
+import Model.Message.Key (Key(PaymentNotDeleted))
getPaymentsAction :: ActionM ()
getPaymentsAction =
@@ -30,3 +35,15 @@ createPaymentAction name cost =
paymentKey <- liftIO . runDb $ createPayment (entityKey user) name cost
json . Message . paymentKeyToText $ paymentKey
)
+
+deletePaymentAction :: Text -> ActionM ()
+deletePaymentAction paymentId =
+ Secure.loggedAction (\user -> do
+ deleted <- liftIO . runDb $ deleteOwnPayment user (textToKey paymentId)
+ if deleted
+ then
+ status ok200
+ else do
+ status badRequest400
+ json . Message . getMessage $ PaymentNotDeleted
+ )