aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorJoris2015-12-31 19:34:29 +0100
committerJoris2015-12-31 19:34:29 +0100
commitb73ba24f3440b81698c9d5c370739d03f958f059 (patch)
tree72caa19d605d9e9af2d43a6f62c177ddb3d0f3b3 /src/server
parent5bfd349bedb9c395cbeb38bb888e379ba36d5d35 (diff)
Fetch all the payments, do the paging only in the UI
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Controller/Payment.hs6
-rw-r--r--src/server/Main.hs5
-rw-r--r--src/server/Model/Payment.hs41
3 files changed, 20 insertions, 32 deletions
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs
index d233aa2..d2a9258 100644
--- a/src/server/Controller/Payment.hs
+++ b/src/server/Controller/Payment.hs
@@ -30,10 +30,10 @@ import qualified Model.Json.PaymentId as JP
import Model.Message
import Model.Message.Key (Key(PaymentNotDeleted))
-getPayments :: Int -> Int -> ActionM ()
-getPayments page perPage =
+getPayments :: ActionM ()
+getPayments =
Secure.loggedAction (\_ -> do
- (liftIO $ runDb (P.getPunctualPayments page perPage)) >>= json
+ (liftIO $ runDb P.getPunctualPayments) >>= json
)
getMonthlyPayments :: ActionM ()
diff --git a/src/server/Main.hs b/src/server/Main.hs
index 3539120..3ac489e 100644
--- a/src/server/Main.hs
+++ b/src/server/Main.hs
@@ -54,10 +54,7 @@ main = do
-- Payments
- get "/payments" $ do
- page <- param "page" :: ActionM Int
- perPage <- param "perPage" :: ActionM Int
- getPayments page perPage
+ get "/payments" getPayments
get "/monthlyPayments" getMonthlyPayments
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
+ ]