aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model
diff options
context:
space:
mode:
authorJoris2015-12-31 19:34:29 +0100
committerJoris2015-12-31 19:34:29 +0100
commitb73ba24f3440b81698c9d5c370739d03f958f059 (patch)
tree72caa19d605d9e9af2d43a6f62c177ddb3d0f3b3 /src/server/Model
parent5bfd349bedb9c395cbeb38bb888e379ba36d5d35 (diff)
Fetch all the payments, do the paging only in the UI
Diffstat (limited to 'src/server/Model')
-rw-r--r--src/server/Model/Payment.hs41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs
index 233cafa..de4a759 100644
--- a/src/server/Model/Payment.hs
+++ b/src/server/Model/Payment.hs
@@ -14,24 +14,18 @@ import Control.Monad.IO.Class (liftIO)
import Database.Persist
import qualified Database.Persist as P
-import Database.Esqueleto
-import qualified Database.Esqueleto as E
import Model.Database
import Model.Frequency
import qualified Model.Json.Payment as P
-getPunctualPayments :: Int -> Int -> Persist [P.Payment]
-getPunctualPayments page perPage = do
- xs <- select $
- from $ \(payment) -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Punctual)
- orderBy [desc (payment ^. PaymentCreation)]
- limit . fromIntegral $ perPage
- offset . fromIntegral $ (page - 1) * perPage
- return payment
- return (map getJsonPayment xs)
+getPunctualPayments :: Persist [P.Payment]
+getPunctualPayments =
+ map getJsonPayment <$> selectList
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Punctual
+ ]
+ [ Desc PaymentCreation ]
getUserMonthlyPayments :: UserId -> Persist [P.Payment]
getUserMonthlyPayments userId =
@@ -39,12 +33,11 @@ getUserMonthlyPayments userId =
getMonthlyPayments :: Persist [Entity Payment]
getMonthlyPayments =
- select $
- from $ \payment -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Monthly)
- orderBy [desc (lower_ (payment ^. PaymentName))]
- return payment
+ selectList
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Monthly
+ ]
+ [ Desc PaymentName ]
getJsonPayment :: Entity Payment -> P.Payment
getJsonPayment paymentEntity =
@@ -79,9 +72,7 @@ deleteOwnPayment user paymentId = do
getPaymentsCount :: Persist Int
getPaymentsCount =
- unValue . head <$>
- (select $
- from $ \payment -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Punctual)
- return countRows) :: Persist Int
+ count
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Punctual
+ ]