diff options
author | Joris | 2016-06-27 14:36:03 +0200 |
---|---|---|
committer | Joris | 2016-06-27 14:36:03 +0200 |
commit | f605541cbaaa3c339eef8f345547bcd653d3f721 (patch) | |
tree | 1e800df7736e482290ca138726595e067e4a5cf9 /src/server/Controller | |
parent | 885dfd7708e338a3220c85b7f22a3ac267aad3f7 (diff) |
Add the edit functionnality on payments
Diffstat (limited to 'src/server/Controller')
-rw-r--r-- | src/server/Controller/Payment.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs index 55edea5..96ac469 100644 --- a/src/server/Controller/Payment.hs +++ b/src/server/Controller/Payment.hs @@ -3,6 +3,7 @@ module Controller.Payment ( list , create + , editOwn , deleteOwn ) where @@ -15,7 +16,6 @@ import Database.Persist import Control.Monad.IO.Class (liftIO) import Data.Text (Text) -import qualified Data.Text.Lazy as TL import qualified Secure @@ -23,8 +23,8 @@ import Json (jsonId) import Model.Database import qualified Model.Payment as Payment -import Model.Message.Key (Key(PaymentNotDeleted)) import qualified Model.Json.CreatePayment as Json +import qualified Model.Json.EditPayment as Json list :: ActionM () list = @@ -33,19 +33,25 @@ list = ) create :: Json.CreatePayment -> ActionM () -create (Json.CreatePayment date name cost frequency) = +create (Json.CreatePayment name cost date frequency) = Secure.loggedAction (\user -> - (liftIO . runDb $ Payment.create (entityKey user) date name cost frequency) >>= jsonId + (liftIO . runDb $ Payment.create (entityKey user) name cost date frequency) >>= jsonId + ) + +editOwn :: Json.EditPayment -> ActionM () +editOwn (Json.EditPayment paymentId name cost date frequency) = + Secure.loggedAction (\user -> do + updated <- liftIO . runDb $ Payment.editOwn (entityKey user) paymentId name cost date frequency + if updated + then status ok200 + else status badRequest400 ) deleteOwn :: Text -> ActionM () deleteOwn paymentId = Secure.loggedAction (\user -> do - deleted <- liftIO . runDb $ Payment.deleteOwn user (textToKey paymentId) + deleted <- liftIO . runDb $ Payment.deleteOwn (entityKey user) (textToKey paymentId) if deleted - then - status ok200 - else do - status badRequest400 - text . TL.pack . show $ PaymentNotDeleted + then status ok200 + else status badRequest400 ) |