aboutsummaryrefslogtreecommitdiff
path: root/server/src/Validation/Payment.hs
diff options
context:
space:
mode:
authorJoris2019-10-09 23:16:00 +0200
committerJoris2019-10-09 23:16:04 +0200
commit7529a18ff0ac443e7f9764b5e2d0f57a5d3a850b (patch)
tree3d5cfc1f2318c2d4f889ee70764929f1a96e4c41 /server/src/Validation/Payment.hs
parente5ac82f4808e974dec5f19fc6f059efaa5214022 (diff)
downloadbudget-7529a18ff0ac443e7f9764b5e2d0f57a5d3a850b.tar.gz
budget-7529a18ff0ac443e7f9764b5e2d0f57a5d3a850b.tar.bz2
budget-7529a18ff0ac443e7f9764b5e2d0f57a5d3a850b.zip
Use common payment validation in the backend
Remove deprecated backend validation
Diffstat (limited to 'server/src/Validation/Payment.hs')
-rw-r--r--server/src/Validation/Payment.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/server/src/Validation/Payment.hs b/server/src/Validation/Payment.hs
new file mode 100644
index 0000000..20e370e
--- /dev/null
+++ b/server/src/Validation/Payment.hs
@@ -0,0 +1,33 @@
+module Validation.Payment
+ ( createPayment
+ , editPayment
+ ) where
+
+import Data.Text (Text)
+import Data.Validation (Validation)
+import qualified Data.Validation as V
+
+import Common.Model (CategoryId, CreatePaymentForm (..),
+ EditPaymentForm (..))
+import qualified Common.Validation.Payment as PaymentValidation
+import Model.CreatePayment (CreatePayment (..))
+import Model.EditPayment (EditPayment (..))
+
+createPayment :: [CategoryId] -> CreatePaymentForm -> Validation Text CreatePayment
+createPayment categories form =
+ CreatePayment
+ <$> PaymentValidation.name (_createPaymentForm_name form)
+ <*> PaymentValidation.cost (_createPaymentForm_cost form)
+ <*> PaymentValidation.date (_createPaymentForm_date form)
+ <*> PaymentValidation.category categories (_createPaymentForm_category form)
+ <*> V.Success (_createPaymentForm_frequency form)
+
+editPayment :: [CategoryId] -> EditPaymentForm -> Validation Text EditPayment
+editPayment categories form =
+ EditPayment
+ <$> V.Success (_editPaymentForm_id form)
+ <*> PaymentValidation.name (_editPaymentForm_name form)
+ <*> PaymentValidation.cost (_editPaymentForm_cost form)
+ <*> PaymentValidation.date (_editPaymentForm_date form)
+ <*> PaymentValidation.category categories (_editPaymentForm_category form)
+ <*> V.Success (_editPaymentForm_frequency form)