aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorJoris2019-10-20 12:02:21 +0200
committerJoris2019-10-20 12:02:21 +0200
commit7aadcc97f9df0e2daccbe8a8726d8bc6c63d67f4 (patch)
tree3637cc06f6378fc3ea04844f15fe43bc04155007 /common/src
parent6e9e34e92a244ab6c38d135d46f9f5bb01391906 (diff)
Add income
Diffstat (limited to 'common/src')
-rw-r--r--common/src/Common/Model.hs3
-rw-r--r--common/src/Common/Model/CreateIncome.hs14
-rw-r--r--common/src/Common/Model/CreateIncomeForm.hs15
-rw-r--r--common/src/Common/Model/EditIncomeForm.hs18
-rw-r--r--common/src/Common/Validation/Income.hs17
-rw-r--r--common/src/Common/Validation/Payment.hs1
6 files changed, 52 insertions, 16 deletions
diff --git a/common/src/Common/Model.hs b/common/src/Common/Model.hs
index 5b71a84..c9f500b 100644
--- a/common/src/Common/Model.hs
+++ b/common/src/Common/Model.hs
@@ -2,11 +2,12 @@ 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.CreateIncomeForm 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.EditIncomeForm as X
import Common.Model.EditPaymentForm as X
import Common.Model.Email as X
import Common.Model.Frequency as X
diff --git a/common/src/Common/Model/CreateIncome.hs b/common/src/Common/Model/CreateIncome.hs
deleted file mode 100644
index 644a51c..0000000
--- a/common/src/Common/Model/CreateIncome.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Common.Model.CreateIncome
- ( CreateIncome(..)
- ) where
-
-import Data.Aeson (FromJSON)
-import Data.Time.Calendar (Day)
-import GHC.Generics (Generic)
-
-data CreateIncome = CreateIncome
- { _createIncome_date :: Day
- , _createIncome_amount :: Int
- } deriving (Show, Generic)
-
-instance FromJSON CreateIncome
diff --git a/common/src/Common/Model/CreateIncomeForm.hs b/common/src/Common/Model/CreateIncomeForm.hs
new file mode 100644
index 0000000..e83bf0a
--- /dev/null
+++ b/common/src/Common/Model/CreateIncomeForm.hs
@@ -0,0 +1,15 @@
+module Common.Model.CreateIncomeForm
+ ( CreateIncomeForm(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+data CreateIncomeForm = CreateIncomeForm
+ { _createIncomeForm_amount :: Text
+ , _createIncomeForm_date :: Text
+ } deriving (Show, Generic)
+
+instance FromJSON CreateIncomeForm
+instance ToJSON CreateIncomeForm
diff --git a/common/src/Common/Model/EditIncomeForm.hs b/common/src/Common/Model/EditIncomeForm.hs
new file mode 100644
index 0000000..ff975fc
--- /dev/null
+++ b/common/src/Common/Model/EditIncomeForm.hs
@@ -0,0 +1,18 @@
+module Common.Model.EditIncomeForm
+ ( EditIncomeForm(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+import Common.Model.Income (IncomeId)
+
+data EditIncomeForm = EditIncomeForm
+ { _editIncomeForm_id :: IncomeId
+ , _editIncomeForm_amount :: Text
+ , _editIncomeForm_date :: Text
+ } deriving (Show, Generic)
+
+instance FromJSON EditIncomeForm
+instance ToJSON EditIncomeForm
diff --git a/common/src/Common/Validation/Income.hs b/common/src/Common/Validation/Income.hs
new file mode 100644
index 0000000..7a58bab
--- /dev/null
+++ b/common/src/Common/Validation/Income.hs
@@ -0,0 +1,17 @@
+module Common.Validation.Income
+ ( amount
+ , date
+ ) where
+
+import Data.Text (Text)
+import Data.Time.Calendar (Day)
+import Data.Validation (Validation)
+import qualified Data.Validation as V
+
+import qualified Common.Validation.Atomic as Atomic
+
+amount :: Text -> Validation Text Int
+amount input = V.bindValidation (Atomic.number input) Atomic.nonNullNumber
+
+date :: Text -> Validation Text Day
+date = Atomic.day
diff --git a/common/src/Common/Validation/Payment.hs b/common/src/Common/Validation/Payment.hs
index 1bb00ce..e3c447a 100644
--- a/common/src/Common/Validation/Payment.hs
+++ b/common/src/Common/Validation/Payment.hs
@@ -14,7 +14,6 @@ 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