aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
authorJoris2015-08-27 20:36:18 +0200
committerJoris2015-08-27 20:36:18 +0200
commitfd86f021e88a00348ac0e03f03d81cb15bf3042b (patch)
treebaf7cbb5cc01fccebc235e0e400cad94eb90de6b /src/server/Controller
parenta2527c34e6b0e719a948cfd36bfee5ffad095a30 (diff)
Server payament delete
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
+ )