aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Controller')
-rw-r--r--src/server/Controller/Payment.hs33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs
index e3f1082..831abbf 100644
--- a/src/server/Controller/Payment.hs
+++ b/src/server/Controller/Payment.hs
@@ -7,25 +7,20 @@ module Controller.Payment
, deleteOwn
) where
-import Web.Scotty
-
-import Network.HTTP.Types.Status (ok200, badRequest400)
-
-import Database.Persist
-
import Control.Monad.IO.Class (liftIO)
import Data.Text (Text)
-
-import qualified Secure
+import Database.Persist
+import Network.HTTP.Types.Status (ok200, badRequest400)
+import Web.Scotty
import Json (jsonId)
-
import Model.Database
-import qualified Model.Payment as Payment
-import qualified Model.PaymentCategory as PaymentCategory
import qualified Model.Json.CreatePayment as Json
import qualified Model.Json.EditPayment as Json
+import qualified Model.Payment as Payment
+import qualified Model.PaymentCategory as PaymentCategory
+import qualified Secure
list :: ActionM ()
list =
@@ -37,7 +32,7 @@ create :: Json.CreatePayment -> ActionM ()
create (Json.CreatePayment name cost date category frequency) =
Secure.loggedAction (\user ->
(liftIO . runDb $ do
- PaymentCategory.set name category
+ PaymentCategory.save name category
Payment.create (entityKey user) name cost date frequency
) >>= jsonId
)
@@ -46,15 +41,11 @@ editOwn :: Json.EditPayment -> ActionM ()
editOwn (Json.EditPayment paymentId name cost date category frequency) =
Secure.loggedAction (\user -> do
updated <- liftIO . runDb $ do
- mbPayment <- fmap entityVal <$> Payment.find paymentId
- case mbPayment of
- Just payment -> do
- edited <- Payment.editOwn (entityKey user) paymentId name cost date frequency
- if edited
- then PaymentCategory.edit (paymentName payment) name category >> return True
- else return edited
- _ ->
- return False
+ edited <- Payment.editOwn (entityKey user) paymentId name cost date frequency
+ _ <- if edited
+ then PaymentCategory.save name category >> return ()
+ else return ()
+ return edited
if updated
then status ok200
else status badRequest400