diff options
author | Joris | 2016-06-26 12:31:24 +0200 |
---|---|---|
committer | Joris | 2016-06-26 12:31:24 +0200 |
commit | 9ec84e3a20c767f6525639f58cd22715e302b88d (patch) | |
tree | a080552859180707472c1a289080857c0a54fc06 /src/server/Model/Payment.hs | |
parent | 5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff) |
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/server/Model/Payment.hs')
-rw-r--r-- | src/server/Model/Payment.hs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs index 28f1a09..51ca152 100644 --- a/src/server/Model/Payment.hs +++ b/src/server/Model/Payment.hs @@ -1,14 +1,15 @@ {-# LANGUAGE OverloadedStrings #-} module Model.Payment - ( getPayments - , getMonthlyPayments - , createPayment - , deleteOwnPayment + ( list + , listMonthly + , create + , deleteOwn ) where import Data.Text (Text) import Data.Time.Clock (getCurrentTime) +import Data.Time.Calendar (Day) import Control.Monad.IO.Class (liftIO) @@ -18,14 +19,14 @@ import Model.Database import Model.Frequency import qualified Model.Json.Payment as P -getPayments :: Persist [P.Payment] -getPayments = +list :: Persist [P.Payment] +list = map getJsonPayment <$> selectList [ PaymentDeletedAt ==. Nothing ] - [ Desc PaymentCreation ] + [] -getMonthlyPayments :: Persist [Entity Payment] -getMonthlyPayments = +listMonthly :: Persist [Entity Payment] +listMonthly = selectList [ PaymentDeletedAt ==. Nothing , PaymentFrequency ==. Monthly @@ -37,20 +38,20 @@ getJsonPayment paymentEntity = let payment = entityVal paymentEntity in P.Payment { P.id = entityKey paymentEntity - , P.creation = paymentCreation payment + , P.date = paymentDate payment , P.name = paymentName payment , P.cost = paymentCost payment , P.userId = paymentUserId payment , P.frequency = paymentFrequency payment } -createPayment :: UserId -> Text -> Int -> Frequency -> Persist PaymentId -createPayment userId name cost frequency = do +create :: UserId -> Day -> Text -> Int -> Frequency -> Persist PaymentId +create userId date name cost frequency = do now <- liftIO getCurrentTime - insert (Payment userId now name cost Nothing frequency) + insert (Payment userId date name cost now Nothing frequency) -deleteOwnPayment :: Entity User -> PaymentId -> Persist Bool -deleteOwnPayment user paymentId = do +deleteOwn :: Entity User -> PaymentId -> Persist Bool +deleteOwn user paymentId = do mbPayment <- get paymentId case mbPayment of Just payment -> |