aboutsummaryrefslogtreecommitdiff
path: root/server/src/Controller/Payment.hs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/Controller/Payment.hs')
-rw-r--r--server/src/Controller/Payment.hs17
1 files changed, 8 insertions, 9 deletions
diff --git a/server/src/Controller/Payment.hs b/server/src/Controller/Payment.hs
index 42a4436..d6aa34f 100644
--- a/server/src/Controller/Payment.hs
+++ b/server/src/Controller/Payment.hs
@@ -8,7 +8,6 @@ module Controller.Payment
import Control.Monad.IO.Class (liftIO)
import qualified Data.Map as M
-import qualified Data.Maybe as Maybe
import Data.Text (Text)
import qualified Data.Time.Calendar as Calendar
import Data.Validation (Validation (Failure, Success))
@@ -77,30 +76,30 @@ create :: CreatePaymentForm -> ActionM ()
create form =
Secure.loggedAction (\user ->
(liftIO . Query.run $ do
- cs <- map _category_id <$> CategoryPersistence.list
+ cs <- map _category_id <$> CategoryPersistence.listAll
case PaymentValidation.createPayment cs form of
Success (CreatePayment name cost date category frequency) ->
Right <$> PaymentPersistence.create (_user_id user) name cost date category frequency
Failure validationError ->
return $ Left validationError
- ) >>= ControllerHelper.jsonOrBadRequest
+ ) >>= ControllerHelper.okOrBadRequest
)
edit :: EditPaymentForm -> ActionM ()
edit form =
Secure.loggedAction (\user ->
(liftIO . Query.run $ do
- cs <- map _category_id <$> CategoryPersistence.list
+ cs <- map _category_id <$> CategoryPersistence.listAll
case PaymentValidation.editPayment cs form of
Success (EditPayment paymentId name cost date category frequency) -> do
- editedPayment <- PaymentPersistence.edit (_user_id user) paymentId name cost date category frequency
- if Maybe.isJust editedPayment then
- return . Right $ editedPayment
+ isSuccess <- PaymentPersistence.edit (_user_id user) paymentId name cost date category frequency
+ return $ if isSuccess then
+ Right ()
else
- return . Left $ Msg.get Msg.Error_PaymentEdit
+ Left $ Msg.get Msg.Error_PaymentEdit
Failure validationError ->
return $ Left validationError
- ) >>= ControllerHelper.jsonOrBadRequest
+ ) >>= ControllerHelper.okOrBadRequest
)
delete :: PaymentId -> ActionM ()