aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model/Income.hs
diff options
context:
space:
mode:
authorJoris2016-08-08 20:58:17 +0200
committerJoris2016-08-08 20:58:17 +0200
commit8816cf758119a6a2073e561c8df297a833630986 (patch)
tree20e63f3c0de15945b818a6d7a78359f9134b5e82 /src/server/Model/Income.hs
parentb54d8e45fc8784d8fa6eaa03f58536b7a19cf70b (diff)
downloadbudget-8816cf758119a6a2073e561c8df297a833630986.tar.gz
budget-8816cf758119a6a2073e561c8df297a833630986.tar.bz2
budget-8816cf758119a6a2073e561c8df297a833630986.zip
Show incomes in a table and update like payments are updated
Diffstat (limited to 'src/server/Model/Income.hs')
-rw-r--r--src/server/Model/Income.hs34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/server/Model/Income.hs b/src/server/Model/Income.hs
index 62ab0ed..f389661 100644
--- a/src/server/Model/Income.hs
+++ b/src/server/Model/Income.hs
@@ -1,8 +1,9 @@
module Model.Income
( getJsonIncome
, getIncomes
- , createIncome
- , deleteOwnIncome
+ , create
+ , editOwn
+ , deleteOwn
) where
import Data.Time.Clock (getCurrentTime)
@@ -23,13 +24,32 @@ getJsonIncome incomeEntity =
getIncomes :: Persist [Entity Income]
getIncomes = selectList [IncomeDeletedAt ==. Nothing] []
-createIncome :: UserId -> Day -> Int -> Persist IncomeId
-createIncome userId date amount = do
+create :: UserId -> Day -> Int -> Persist IncomeId
+create userId date amount = do
now <- liftIO getCurrentTime
- insert (Income userId date amount now Nothing)
+ insert (Income userId date amount now Nothing Nothing)
-deleteOwnIncome :: Entity User -> IncomeId -> Persist Bool
-deleteOwnIncome user incomeId = do
+editOwn :: UserId -> IncomeId -> Day -> Int -> Persist Bool
+editOwn userId incomeId date amount = do
+ mbIncome <- get incomeId
+ case mbIncome of
+ Just income ->
+ if incomeUserId income == userId
+ then do
+ now <- liftIO getCurrentTime
+ update incomeId
+ [ IncomeEditedAt =. Just now
+ , IncomeDate =. date
+ , IncomeAmount =. amount
+ ]
+ return True
+ else
+ return False
+ Nothing ->
+ return False
+
+deleteOwn :: Entity User -> IncomeId -> Persist Bool
+deleteOwn user incomeId = do
mbIncome <- get incomeId
case mbIncome of
Just income ->