aboutsummaryrefslogtreecommitdiff
path: root/src/common/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Model')
-rw-r--r--src/common/Model/Category.hs26
-rw-r--r--src/common/Model/CreateCategory.hs16
-rw-r--r--src/common/Model/CreateIncome.hs16
-rw-r--r--src/common/Model/CreatePayment.hs23
-rw-r--r--src/common/Model/Currency.hs14
-rw-r--r--src/common/Model/EditCategory.hs19
-rw-r--r--src/common/Model/EditIncome.hs19
-rw-r--r--src/common/Model/EditPayment.hs25
-rw-r--r--src/common/Model/Frequency.hs16
-rw-r--r--src/common/Model/Income.hs29
-rw-r--r--src/common/Model/Init.hs28
-rw-r--r--src/common/Model/InitResult.hs19
-rw-r--r--src/common/Model/Payment.hs33
-rw-r--r--src/common/Model/PaymentCategory.hs27
-rw-r--r--src/common/Model/SignIn.hs16
-rw-r--r--src/common/Model/User.hs29
16 files changed, 355 insertions, 0 deletions
diff --git a/src/common/Model/Category.hs b/src/common/Model/Category.hs
new file mode 100644
index 0000000..53a6bdb
--- /dev/null
+++ b/src/common/Model/Category.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.Category
+ ( CategoryId
+ , Category(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Int (Int64)
+import Data.Text (Text)
+import Data.Time (UTCTime)
+import GHC.Generics (Generic)
+
+type CategoryId = Int64
+
+data Category = Category
+ { _category_id :: CategoryId
+ , _category_name :: Text
+ , _category_color :: Text
+ , _category_createdAt :: UTCTime
+ , _category_editedAt :: Maybe UTCTime
+ , _category_deletedAt :: Maybe UTCTime
+ } deriving (Show, Generic)
+
+instance FromJSON Category
+instance ToJSON Category
diff --git a/src/common/Model/CreateCategory.hs b/src/common/Model/CreateCategory.hs
new file mode 100644
index 0000000..bfe24c5
--- /dev/null
+++ b/src/common/Model/CreateCategory.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+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/src/common/Model/CreateIncome.hs b/src/common/Model/CreateIncome.hs
new file mode 100644
index 0000000..4ee3a50
--- /dev/null
+++ b/src/common/Model/CreateIncome.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+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/src/common/Model/CreatePayment.hs b/src/common/Model/CreatePayment.hs
new file mode 100644
index 0000000..b5b6256
--- /dev/null
+++ b/src/common/Model/CreatePayment.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.CreatePayment
+ ( CreatePayment(..)
+ ) where
+
+import Data.Aeson (FromJSON)
+import Data.Text (Text)
+import Data.Time.Calendar (Day)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (CategoryId)
+import Common.Model.Frequency (Frequency)
+
+data CreatePayment = CreatePayment
+ { _createPayment_name :: Text
+ , _createPayment_cost :: Int
+ , _createPayment_date :: Day
+ , _createPayment_category :: CategoryId
+ , _createPayment_frequency :: Frequency
+ } deriving (Show, Generic)
+
+instance FromJSON CreatePayment
diff --git a/src/common/Model/Currency.hs b/src/common/Model/Currency.hs
new file mode 100644
index 0000000..7c12545
--- /dev/null
+++ b/src/common/Model/Currency.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.Currency
+ ( Currency(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+newtype Currency = Currency Text deriving (Show, Generic)
+
+instance FromJSON Currency
+instance ToJSON Currency
diff --git a/src/common/Model/EditCategory.hs b/src/common/Model/EditCategory.hs
new file mode 100644
index 0000000..2a3a697
--- /dev/null
+++ b/src/common/Model/EditCategory.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+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/src/common/Model/EditIncome.hs b/src/common/Model/EditIncome.hs
new file mode 100644
index 0000000..a55c39e
--- /dev/null
+++ b/src/common/Model/EditIncome.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.EditIncome
+ ( EditIncome(..)
+ ) where
+
+import Data.Aeson (FromJSON)
+import Data.Time.Calendar (Day)
+import GHC.Generics (Generic)
+
+import Common.Model.Income (IncomeId)
+
+data EditIncome = EditIncome
+ { _editIncome_id :: IncomeId
+ , _editIncome_date :: Day
+ , _editIncome_amount :: Int
+ } deriving (Show, Generic)
+
+instance FromJSON EditIncome
diff --git a/src/common/Model/EditPayment.hs b/src/common/Model/EditPayment.hs
new file mode 100644
index 0000000..172c0c1
--- /dev/null
+++ b/src/common/Model/EditPayment.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.EditPayment
+ ( EditPayment(..)
+ ) where
+
+import Data.Aeson (FromJSON)
+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
diff --git a/src/common/Model/Frequency.hs b/src/common/Model/Frequency.hs
new file mode 100644
index 0000000..7c46605
--- /dev/null
+++ b/src/common/Model/Frequency.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.Frequency
+ ( Frequency(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import GHC.Generics (Generic)
+
+data Frequency =
+ Punctual
+ | Monthly
+ deriving (Eq, Read, Show, Generic)
+
+instance FromJSON Frequency
+instance ToJSON Frequency
diff --git a/src/common/Model/Income.hs b/src/common/Model/Income.hs
new file mode 100644
index 0000000..280812f
--- /dev/null
+++ b/src/common/Model/Income.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.Income
+ ( IncomeId
+ , Income(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Int (Int64)
+import Data.Time (UTCTime)
+import Data.Time.Calendar (Day)
+import GHC.Generics (Generic)
+
+import Common.Model.User (UserId)
+
+type IncomeId = Int64
+
+data Income = Income
+ { _income_id :: IncomeId
+ , _income_userId :: UserId
+ , _income_date :: Day
+ , _income_amount :: Int
+ , _income_createdAt :: UTCTime
+ , _income_editedAt :: Maybe UTCTime
+ , _income_deletedAt :: Maybe UTCTime
+ } deriving (Show, Generic)
+
+instance FromJSON Income
+instance ToJSON Income
diff --git a/src/common/Model/Init.hs b/src/common/Model/Init.hs
new file mode 100644
index 0000000..68fcfb8
--- /dev/null
+++ b/src/common/Model/Init.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.Init
+ ( Init(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (Category)
+import Common.Model.Currency (Currency)
+import Common.Model.Income (Income)
+import Common.Model.Payment (Payment)
+import Common.Model.PaymentCategory (PaymentCategory)
+import Common.Model.User (UserId, User)
+
+data Init = Init
+ { _init_users :: [User]
+ , _init_currentUser :: UserId
+ , _init_payments :: [Payment]
+ , _init_incomes :: [Income]
+ , _init_categories :: [Category]
+ , _init_paymentCategories :: [PaymentCategory]
+ , _init_currency :: Currency
+ } deriving (Show, Generic)
+
+instance FromJSON Init
+instance ToJSON Init
diff --git a/src/common/Model/InitResult.hs b/src/common/Model/InitResult.hs
new file mode 100644
index 0000000..43c16f9
--- /dev/null
+++ b/src/common/Model/InitResult.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.InitResult
+ ( InitResult(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+import Common.Model.Init (Init)
+
+data InitResult =
+ InitSuccess Init
+ | InitEmpty (Either Text (Maybe Text))
+ deriving (Show, Generic)
+
+instance FromJSON InitResult
+instance ToJSON InitResult
diff --git a/src/common/Model/Payment.hs b/src/common/Model/Payment.hs
new file mode 100644
index 0000000..804b501
--- /dev/null
+++ b/src/common/Model/Payment.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.Payment
+ ( PaymentId
+ , Payment(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Int (Int64)
+import Data.Text (Text)
+import Data.Time (UTCTime)
+import Data.Time.Calendar (Day)
+import GHC.Generics (Generic)
+
+import Common.Model.Frequency
+import Common.Model.User (UserId)
+
+type PaymentId = Int64
+
+data Payment = Payment
+ { _payment_id :: PaymentId
+ , _payment_user :: UserId
+ , _payment_name :: Text
+ , _payment_cost :: Int
+ , _payment_date :: Day
+ , _payment_frequency :: Frequency
+ , _payment_createdAt :: UTCTime
+ , _payment_editedAt :: Maybe UTCTime
+ , _payment_deletedAt :: Maybe UTCTime
+ } deriving (Show, Generic)
+
+instance FromJSON Payment
+instance ToJSON Payment
diff --git a/src/common/Model/PaymentCategory.hs b/src/common/Model/PaymentCategory.hs
new file mode 100644
index 0000000..a0e94f9
--- /dev/null
+++ b/src/common/Model/PaymentCategory.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.PaymentCategory
+ ( PaymentCategoryId
+ , PaymentCategory(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Int (Int64)
+import Data.Text (Text)
+import Data.Time (UTCTime)
+import GHC.Generics (Generic)
+
+import Common.Model.Category (CategoryId)
+
+type PaymentCategoryId = Int64
+
+data PaymentCategory = PaymentCategory
+ { _paymentCategory_id :: PaymentCategoryId
+ , _paymentCategory_name :: Text
+ , _paymentCategory_category :: CategoryId
+ , _paymentCategory_createdAt :: UTCTime
+ , _paymentCategory_editedAt :: Maybe UTCTime
+ } deriving (Show, Generic)
+
+instance FromJSON PaymentCategory
+instance ToJSON PaymentCategory
diff --git a/src/common/Model/SignIn.hs b/src/common/Model/SignIn.hs
new file mode 100644
index 0000000..f4da97f
--- /dev/null
+++ b/src/common/Model/SignIn.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.SignIn
+ ( SignIn(..)
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+data SignIn = SignIn
+ { _signIn_email :: Text
+ } deriving (Show, Generic)
+
+instance FromJSON SignIn
+instance ToJSON SignIn
diff --git a/src/common/Model/User.hs b/src/common/Model/User.hs
new file mode 100644
index 0000000..8c64bc2
--- /dev/null
+++ b/src/common/Model/User.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Common.Model.User
+ ( UserId
+ , User(..)
+ , find
+ ) where
+
+import Data.Aeson (FromJSON, ToJSON)
+import qualified Data.List as L
+import Data.Int (Int64)
+import Data.Text (Text)
+import Data.Time (UTCTime)
+import GHC.Generics (Generic)
+
+type UserId = Int64
+
+data User = User
+ { _user_id :: UserId
+ , _user_creation :: UTCTime
+ , _user_email :: Text
+ , _user_name :: Text
+ } deriving (Show, Generic)
+
+instance FromJSON User
+instance ToJSON User
+
+find :: UserId -> [User] -> Maybe User
+find userId users = L.find ((== userId) . _user_id) users