From fd86f021e88a00348ac0e03f03d81cb15bf3042b Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 27 Aug 2015 20:36:18 +0200 Subject: Server payament delete --- src/server/Controller/Payment.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/server/Controller') 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 + ) -- cgit v1.2.3