aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJoris2019-12-08 11:39:37 +0100
committerJoris2019-12-08 11:39:37 +0100
commit316bda10c6bec8b5ccc9e23f1f677c076205f046 (patch)
tree98da1d18834108af50f80ca6fa5c0f4facc42472 /common
parente622e8fdd2e40b4306b5cc724d8dfb76bf976242 (diff)
downloadbudget-316bda10c6bec8b5ccc9e23f1f677c076205f046.tar.gz
budget-316bda10c6bec8b5ccc9e23f1f677c076205f046.tar.bz2
budget-316bda10c6bec8b5ccc9e23f1f677c076205f046.zip
Add category page
Diffstat (limited to 'common')
-rw-r--r--common/common.cabal6
-rw-r--r--common/src/Common/Model.hs45
-rw-r--r--common/src/Common/Model/Category.hs2
-rw-r--r--common/src/Common/Model/CategoryPage.hs17
-rw-r--r--common/src/Common/Model/CreateCategory.hs14
-rw-r--r--common/src/Common/Model/CreateCategoryForm.hs15
-rw-r--r--common/src/Common/Model/EditCategory.hs17
-rw-r--r--common/src/Common/Model/EditCategoryForm.hs18
-rw-r--r--common/src/Common/Validation/Atomic.hs5
-rw-r--r--common/src/Common/Validation/Category.hs15
10 files changed, 98 insertions, 56 deletions
diff --git a/common/common.cabal b/common/common.cabal
index 17a0ee1..fdede8f 100644
--- a/common/common.cabal
+++ b/common/common.cabal
@@ -31,6 +31,7 @@ Library
Exposed-modules:
Common.Model
+ Common.Model.CreateCategoryForm
Common.Model.CreateIncomeForm
Common.Model.CreatePaymentForm
Common.Model.Email
@@ -42,6 +43,7 @@ Library
Common.Util.Time
Common.Util.Validation
Common.Validation.Atomic
+ Common.Validation.Category
Common.Validation.Income
Common.Validation.Payment
Common.Validation.SignIn
@@ -52,9 +54,9 @@ Library
Common.Message.Lang
Common.Message.Translation
Common.Model.Category
- Common.Model.CreateCategory
+ Common.Model.CategoryPage
Common.Model.Currency
- Common.Model.EditCategory
+ Common.Model.EditCategoryForm
Common.Model.EditIncome
Common.Model.EditIncomeForm
Common.Model.EditPaymentForm
diff --git a/common/src/Common/Model.hs b/common/src/Common/Model.hs
index 00d30f6..73cbf6c 100644
--- a/common/src/Common/Model.hs
+++ b/common/src/Common/Model.hs
@@ -1,24 +1,25 @@
module Common.Model (module X) where
-import Common.Model.Category as X
-import Common.Model.CreateCategory 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.ExceedingPayer as X
-import Common.Model.Frequency as X
-import Common.Model.Income as X
-import Common.Model.IncomeHeader as X
-import Common.Model.IncomePage as X
-import Common.Model.Init as X
-import Common.Model.InitResult as X
-import Common.Model.Payment as X
-import Common.Model.PaymentHeader as X
-import Common.Model.PaymentPage as X
-import Common.Model.SignInForm as X
-import Common.Model.User as X
+import Common.Model.Category as X
+import Common.Model.CategoryPage as X
+import Common.Model.CreateCategoryForm as X
+import Common.Model.CreateIncomeForm as X
+import Common.Model.CreatePaymentForm as X
+import Common.Model.Currency as X
+import Common.Model.EditCategoryForm 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.ExceedingPayer as X
+import Common.Model.Frequency as X
+import Common.Model.Income as X
+import Common.Model.IncomeHeader as X
+import Common.Model.IncomePage as X
+import Common.Model.Init as X
+import Common.Model.InitResult as X
+import Common.Model.Payment as X
+import Common.Model.PaymentHeader as X
+import Common.Model.PaymentPage as X
+import Common.Model.SignInForm as X
+import Common.Model.User as X
diff --git a/common/src/Common/Model/Category.hs b/common/src/Common/Model/Category.hs
index db1da53..cc3f795 100644
--- a/common/src/Common/Model/Category.hs
+++ b/common/src/Common/Model/Category.hs
@@ -18,7 +18,7 @@ data Category = Category
, _category_createdAt :: UTCTime
, _category_editedAt :: Maybe UTCTime
, _category_deletedAt :: Maybe UTCTime
- } deriving (Show, Generic)
+ } deriving (Eq, Show, Generic)
instance FromJSON Category
instance ToJSON Category
diff --git a/common/src/Common/Model/CategoryPage.hs b/common/src/Common/Model/CategoryPage.hs
new file mode 100644
index 0000000..476b4ce
--- /dev/null
+++ b/common/src/Common/Model/CategoryPage.hs
@@ -0,0 +1,17 @@
+module Common.Model.CategoryPage
+ ( CategoryPage(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (Category)
+
+data CategoryPage = CategoryPage
+ { _categoryPage_page :: Int
+ , _categoryPage_categories :: [Category]
+ , _categoryPage_totalCount :: Int
+ } deriving (Eq, Show, Generic)
+
+instance FromJSON CategoryPage
+instance ToJSON CategoryPage
diff --git a/common/src/Common/Model/CreateCategory.hs b/common/src/Common/Model/CreateCategory.hs
deleted file mode 100644
index 51bd2a0..0000000
--- a/common/src/Common/Model/CreateCategory.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Common.Model.CreateCategory
- ( CreateCategory(..)
- ) where
-
-import Data.Aeson (FromJSON)
-import Data.Text (Text)
-import GHC.Generics (Generic)
-
-data CreateCategory = CreateCategory
- { _createCategory_name :: Text
- , _createCategory_color :: Text
- } deriving (Show, Generic)
-
-instance FromJSON CreateCategory
diff --git a/common/src/Common/Model/CreateCategoryForm.hs b/common/src/Common/Model/CreateCategoryForm.hs
new file mode 100644
index 0000000..4668ef4
--- /dev/null
+++ b/common/src/Common/Model/CreateCategoryForm.hs
@@ -0,0 +1,15 @@
+module Common.Model.CreateCategoryForm
+ ( CreateCategoryForm(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+data CreateCategoryForm = CreateCategoryForm
+ { _createCategoryForm_name :: Text
+ , _createCategoryForm_color :: Text
+ } deriving (Show, Generic)
+
+instance FromJSON CreateCategoryForm
+instance ToJSON CreateCategoryForm
diff --git a/common/src/Common/Model/EditCategory.hs b/common/src/Common/Model/EditCategory.hs
deleted file mode 100644
index 8b9d9eb..0000000
--- a/common/src/Common/Model/EditCategory.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Common.Model.EditCategory
- ( EditCategory(..)
- ) where
-
-import Data.Aeson (FromJSON)
-import Data.Text (Text)
-import GHC.Generics (Generic)
-
-import Common.Model.Category (CategoryId)
-
-data EditCategory = EditCategory
- { _editCategory_id :: CategoryId
- , _editCategory_name :: Text
- , _editCategory_color :: Text
- } deriving (Show, Generic)
-
-instance FromJSON EditCategory
diff --git a/common/src/Common/Model/EditCategoryForm.hs b/common/src/Common/Model/EditCategoryForm.hs
new file mode 100644
index 0000000..a2ceca0
--- /dev/null
+++ b/common/src/Common/Model/EditCategoryForm.hs
@@ -0,0 +1,18 @@
+module Common.Model.EditCategoryForm
+ ( EditCategoryForm(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (CategoryId)
+
+data EditCategoryForm = EditCategoryForm
+ { _editCategoryForm_id :: CategoryId
+ , _editCategoryForm_name :: Text
+ , _editCategoryForm_color :: Text
+ } deriving (Show, Generic)
+
+instance FromJSON EditCategoryForm
+instance ToJSON EditCategoryForm
diff --git a/common/src/Common/Validation/Atomic.hs b/common/src/Common/Validation/Atomic.hs
index 3516668..2a356df 100644
--- a/common/src/Common/Validation/Atomic.hs
+++ b/common/src/Common/Validation/Atomic.hs
@@ -4,6 +4,7 @@ module Common.Validation.Atomic
, number
, nonNullNumber
, day
+ , color
) where
import Data.Text (Text)
@@ -45,3 +46,7 @@ day str =
case Time.parseDay str of
Just d -> V.Success d
Nothing -> V.Failure $ Msg.get Msg.Form_InvalidDate
+
+-- TODO: validate
+color :: Text -> Validation Text Text
+color str = V.Success str
diff --git a/common/src/Common/Validation/Category.hs b/common/src/Common/Validation/Category.hs
new file mode 100644
index 0000000..f9e6ab4
--- /dev/null
+++ b/common/src/Common/Validation/Category.hs
@@ -0,0 +1,15 @@
+module Common.Validation.Category
+ ( name
+ , color
+ ) where
+
+import Data.Text (Text)
+import Data.Validation (Validation)
+
+import qualified Common.Validation.Atomic as Atomic
+
+name :: Text -> Validation Text Text
+name = Atomic.nonEmpty
+
+color :: Text -> Validation Text Text
+color = Atomic.color