aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Model')
-rw-r--r--src/server/Model/Database.hs4
-rw-r--r--src/server/Model/Income.hs12
-rw-r--r--src/server/Model/Json/AddIncome.hs17
-rw-r--r--src/server/Model/Json/Income.hs5
-rw-r--r--src/server/Model/Message/Key.hs12
-rw-r--r--src/server/Model/Message/Translations.hs47
6 files changed, 76 insertions, 21 deletions
diff --git a/src/server/Model/Database.hs b/src/server/Model/Database.hs
index 0915afe..5df925a 100644
--- a/src/server/Model/Database.hs
+++ b/src/server/Model/Database.hs
@@ -16,6 +16,7 @@ import Control.Monad.Trans.Resource (runResourceT, ResourceT)
import Data.Text
import Data.Time.Clock (UTCTime)
+import Data.Time.Calendar (Day)
import Data.Int (Int64)
import Database.Persist.Sqlite
@@ -55,8 +56,9 @@ Job
deriving Show
Income
userId UserId
- creation UTCTime
+ date Day
amount Int
+ createdAt UTCTime
deletedAt UTCTime Maybe
deriving Show
|]
diff --git a/src/server/Model/Income.hs b/src/server/Model/Income.hs
index c0cac45..119a44f 100644
--- a/src/server/Model/Income.hs
+++ b/src/server/Model/Income.hs
@@ -5,7 +5,8 @@ module Model.Income
, deleteOwnIncome
) where
-import Data.Time.Clock (UTCTime, getCurrentTime)
+import Data.Time.Clock (getCurrentTime)
+import Data.Time.Calendar (Day)
import Control.Monad.IO.Class (liftIO)
@@ -16,15 +17,16 @@ import qualified Model.Json.Income as Json
getJsonIncome :: Entity Income -> Json.Income
getJsonIncome incomeEntity =
- Json.Income (entityKey incomeEntity) (incomeUserId income) (incomeCreation income) (incomeAmount income)
+ Json.Income (entityKey incomeEntity) (incomeUserId income) (incomeDate income) (incomeAmount income)
where income = entityVal incomeEntity
getIncomes :: Persist [Entity Income]
getIncomes = selectList [IncomeDeletedAt ==. Nothing] []
-addIncome :: UserId -> UTCTime -> Int -> Persist IncomeId
-addIncome userId creation amount = do
- insert (Income userId creation amount Nothing)
+addIncome :: UserId -> Day -> Int -> Persist IncomeId
+addIncome userId day amount = do
+ now <- liftIO getCurrentTime
+ insert (Income userId day amount now Nothing)
deleteOwnIncome :: Entity User -> IncomeId -> Persist Bool
deleteOwnIncome user incomeId = do
diff --git a/src/server/Model/Json/AddIncome.hs b/src/server/Model/Json/AddIncome.hs
new file mode 100644
index 0000000..6570ba9
--- /dev/null
+++ b/src/server/Model/Json/AddIncome.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Model.Json.AddIncome
+ ( AddIncome(..)
+ ) where
+
+import GHC.Generics
+
+import Data.Aeson
+import Data.Time.Calendar (Day)
+
+data AddIncome = AddIncome
+ { day :: Day
+ , amount :: Int
+ } deriving (Show, Generic)
+
+instance FromJSON AddIncome
diff --git a/src/server/Model/Json/Income.hs b/src/server/Model/Json/Income.hs
index 6ad331a..e80ab63 100644
--- a/src/server/Model/Json/Income.hs
+++ b/src/server/Model/Json/Income.hs
@@ -7,16 +7,15 @@ module Model.Json.Income
import GHC.Generics
import Data.Aeson
-import Data.Time.Clock (UTCTime)
+import Data.Time.Calendar (Day)
import Model.Database (IncomeId, UserId)
data Income = Income
{ id :: IncomeId
, userId :: UserId
- , creation :: UTCTime
+ , day :: Day
, amount :: Int
} deriving (Show, Generic)
-instance FromJSON Income
instance ToJSON Income
diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs
index 4a49900..d34eea3 100644
--- a/src/server/Model/Message/Key.hs
+++ b/src/server/Model/Message/Key.hs
@@ -51,7 +51,6 @@ data Key =
| CategoryRequired
| CostRequired
- | DateValidationError
-- Payments
@@ -77,12 +76,21 @@ data Key =
-- Income
| CumulativeIncomesSince
- | AddIncome
| Income
| MonthlyNetIncomes
| IncomeNotDeleted
| Creation
| Amount
+ | Delete
+
+ -- Form
+
+ | Empty
+ | InvalidString
+ | InvalidDate
+ | InvalidInt
+ | SmallerIntThan
+ | GreaterIntThan
-- Http error
diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs
index 3ceb7a3..2060611 100644
--- a/src/server/Model/Message/Translations.hs
+++ b/src/server/Model/Message/Translations.hs
@@ -198,11 +198,6 @@ m l CostRequired =
English -> "Type a positive cost."
French -> "Entre un coût positif."
-m l DateValidationError =
- case l of
- English -> "The date must be day/month/year"
- French -> "La date doit avoir la forme jour/mois/année"
-
-- Payments
m l Add =
@@ -289,11 +284,6 @@ m l CumulativeIncomesSince =
English -> "Cumulative incomes since {0}"
French -> "Revenus nets cumulés depuis le {0}"
-m l AddIncome =
- case l of
- English -> "Add a monthly income"
- French -> "Ajouter un revenu mensuel net"
-
m l Income =
case l of
English -> "Income"
@@ -319,6 +309,43 @@ m l Amount =
English -> "Amount"
French -> "Montant"
+m l Delete =
+ case l of
+ English -> "Delete"
+ French -> "Supprimer"
+
+-- Form error
+
+m l Empty =
+ case l of
+ English -> "Required field"
+ French -> "Champ requis"
+
+m l InvalidString =
+ case l of
+ English -> "String required"
+ French -> "Chaîne de caractères requise"
+
+m l InvalidDate =
+ case l of
+ English -> "day/month/year required"
+ French -> "jour/mois/année requis"
+
+m l InvalidInt =
+ case l of
+ English -> "Integer required"
+ French -> "Entier requis"
+
+m l SmallerIntThan =
+ case l of
+ English -> "Integer bigger than {0} required"
+ French -> "Entier supérieur à {0} requis"
+
+m l GreaterIntThan =
+ case l of
+ English -> "Integer smaller than {0} required"
+ French -> "Entier inférieur à {0} requis"
+
-- Http error
m l Timeout =