aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'common/src')
-rw-r--r--common/src/Common/Model.hs38
-rw-r--r--common/src/Common/Model/CreatePayment.hs34
-rw-r--r--common/src/Common/Model/CreatePaymentForm.hs21
-rw-r--r--common/src/Common/Model/EditPayment.hs24
-rw-r--r--common/src/Common/Model/EditPaymentForm.hs23
-rw-r--r--common/src/Common/Validation/Payment.hs15
6 files changed, 76 insertions, 79 deletions
diff --git a/common/src/Common/Model.hs b/common/src/Common/Model.hs
index 1abc3e3..5b71a84 100644
--- a/common/src/Common/Model.hs
+++ b/common/src/Common/Model.hs
@@ -1,21 +1,21 @@
module Common.Model (module X) where
-import Common.Model.Category as X
-import Common.Model.CreateCategory as X
-import Common.Model.CreateIncome as X
-import Common.Model.CreatePayment as X
-import Common.Model.Currency as X
-import Common.Model.EditCategory as X
-import Common.Model.EditIncome as X
-import Common.Model.EditPayment as X
-import Common.Model.Email as X
-import Common.Model.Frequency as X
-import Common.Model.Income as X
-import Common.Model.Init as X
-import Common.Model.InitResult as X
-import Common.Model.Payer as X
-import Common.Model.Payment as X
-import Common.Model.PaymentCategory as X
-import Common.Model.SavedPayment as X
-import Common.Model.SignInForm as X
-import Common.Model.User as X
+import Common.Model.Category as X
+import Common.Model.CreateCategory as X
+import Common.Model.CreateIncome as X
+import Common.Model.CreatePaymentForm as X
+import Common.Model.Currency as X
+import Common.Model.EditCategory as X
+import Common.Model.EditIncome as X
+import Common.Model.EditPaymentForm as X
+import Common.Model.Email as X
+import Common.Model.Frequency as X
+import Common.Model.Income as X
+import Common.Model.Init as X
+import Common.Model.InitResult as X
+import Common.Model.Payer as X
+import Common.Model.Payment as X
+import Common.Model.PaymentCategory as X
+import Common.Model.SavedPayment as X
+import Common.Model.SignInForm as X
+import Common.Model.User as X
diff --git a/common/src/Common/Model/CreatePayment.hs b/common/src/Common/Model/CreatePayment.hs
deleted file mode 100644
index c61423c..0000000
--- a/common/src/Common/Model/CreatePayment.hs
+++ /dev/null
@@ -1,34 +0,0 @@
-module Common.Model.CreatePayment
- ( CreatePaymentError(..)
- , CreatePayment(..)
- ) where
-
-import Data.Aeson (FromJSON, ToJSON)
-import Data.Text (Text)
-import Data.Time.Calendar (Day)
-import GHC.Generics (Generic)
-
-import Common.Model.Category (CategoryId)
-import Common.Model.Frequency (Frequency)
-
-data CreatePaymentError = CreatePaymentError
- { _createPaymentError_name :: Maybe Text
- , _createPaymentError_cost :: Maybe Text
- , _createPaymentError_date :: Maybe Text
- , _createPaymentError_category :: Maybe Text
- , _createPaymentError_frequency :: Maybe Text
- } deriving (Show, Generic)
-
-instance FromJSON CreatePaymentError
-instance ToJSON CreatePaymentError
-
-data CreatePayment = CreatePayment
- { _createPayment_name :: Text
- , _createPayment_cost :: Int
- , _createPayment_date :: Day
- , _createPayment_category :: CategoryId
- , _createPayment_frequency :: Frequency
- } deriving (Show, Generic)
-
-instance FromJSON CreatePayment
-instance ToJSON CreatePayment
diff --git a/common/src/Common/Model/CreatePaymentForm.hs b/common/src/Common/Model/CreatePaymentForm.hs
new file mode 100644
index 0000000..60c5423
--- /dev/null
+++ b/common/src/Common/Model/CreatePaymentForm.hs
@@ -0,0 +1,21 @@
+module Common.Model.CreatePaymentForm
+ ( CreatePaymentForm(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (CategoryId)
+import Common.Model.Frequency (Frequency)
+
+data CreatePaymentForm = CreatePaymentForm
+ { _createPaymentForm_name :: Text
+ , _createPaymentForm_cost :: Text
+ , _createPaymentForm_date :: Text
+ , _createPaymentForm_category :: CategoryId
+ , _createPaymentForm_frequency :: Frequency
+ } deriving (Show, Generic)
+
+instance FromJSON CreatePaymentForm
+instance ToJSON CreatePaymentForm
diff --git a/common/src/Common/Model/EditPayment.hs b/common/src/Common/Model/EditPayment.hs
deleted file mode 100644
index 8860b84..0000000
--- a/common/src/Common/Model/EditPayment.hs
+++ /dev/null
@@ -1,24 +0,0 @@
-module Common.Model.EditPayment
- ( EditPayment(..)
- ) where
-
-import Data.Aeson (FromJSON, ToJSON)
-import Data.Text (Text)
-import Data.Time.Calendar (Day)
-import GHC.Generics (Generic)
-
-import Common.Model.Category (CategoryId)
-import Common.Model.Frequency (Frequency)
-import Common.Model.Payment (PaymentId)
-
-data EditPayment = EditPayment
- { _editPayment_id :: PaymentId
- , _editPayment_name :: Text
- , _editPayment_cost :: Int
- , _editPayment_date :: Day
- , _editPayment_category :: CategoryId
- , _editPayment_frequency :: Frequency
- } deriving (Show, Generic)
-
-instance FromJSON EditPayment
-instance ToJSON EditPayment
diff --git a/common/src/Common/Model/EditPaymentForm.hs b/common/src/Common/Model/EditPaymentForm.hs
new file mode 100644
index 0000000..168c9ff
--- /dev/null
+++ b/common/src/Common/Model/EditPaymentForm.hs
@@ -0,0 +1,23 @@
+module Common.Model.EditPaymentForm
+ ( EditPaymentForm(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (CategoryId)
+import Common.Model.Frequency (Frequency)
+import Common.Model.Payment (PaymentId)
+
+data EditPaymentForm = EditPaymentForm
+ { _editPaymentForm_id :: PaymentId
+ , _editPaymentForm_name :: Text
+ , _editPaymentForm_cost :: Text
+ , _editPaymentForm_date :: Text
+ , _editPaymentForm_category :: CategoryId
+ , _editPaymentForm_frequency :: Frequency
+ } deriving (Show, Generic)
+
+instance FromJSON EditPaymentForm
+instance ToJSON EditPaymentForm
diff --git a/common/src/Common/Validation/Payment.hs b/common/src/Common/Validation/Payment.hs
index b6c1d30..1bb00ce 100644
--- a/common/src/Common/Validation/Payment.hs
+++ b/common/src/Common/Validation/Payment.hs
@@ -2,20 +2,31 @@ module Common.Validation.Payment
( name
, cost
, date
+ , category
) where
import Data.Text (Text)
import Data.Time.Calendar (Day)
import Data.Validation (Validation)
-import qualified Data.Validation as Validation
+import qualified Data.Validation as V
+import Common.Model (CategoryId)
+import qualified Common.Msg as Msg
import qualified Common.Validation.Atomic as Atomic
+
name :: Text -> Validation Text Text
name = Atomic.nonEmpty
cost :: Text -> Validation Text Int
-cost input = Validation.bindValidation (Atomic.number input) Atomic.nonNullNumber
+cost input = V.bindValidation (Atomic.number input) Atomic.nonNullNumber
date :: Text -> Validation Text Day
date = Atomic.day
+
+category :: [CategoryId] -> CategoryId -> Validation Text CategoryId
+category cs c =
+ if elem c cs then
+ V.Success c
+ else
+ V.Failure $ Msg.get Msg.Form_InvalidCategory