aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Controller')
-rw-r--r--src/server/Controller/Payment.hs26
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
)