aboutsummaryrefslogtreecommitdiff
path: root/server/src/Persistence
diff options
context:
space:
mode:
authorJoris2019-11-06 19:44:15 +0100
committerJoris2019-11-06 19:44:15 +0100
commitf4f24158a46d8c0975f1b8813bbdbbeebad8c108 (patch)
treed0aeaa3a920caaff7408a1f6cd12b45f21cb2620 /server/src/Persistence
parent58f6c4e25f5f20f1b608242c83786e2f13947804 (diff)
Show the payment table with server side paging
Diffstat (limited to 'server/src/Persistence')
-rw-r--r--server/src/Persistence/Income.hs3
-rw-r--r--server/src/Persistence/Payment.hs25
2 files changed, 24 insertions, 4 deletions
diff --git a/server/src/Persistence/Income.hs b/server/src/Persistence/Income.hs
index 4ae3228..cb2ef10 100644
--- a/server/src/Persistence/Income.hs
+++ b/server/src/Persistence/Income.hs
@@ -60,9 +60,6 @@ listAll =
SQLite.query_ conn "SELECT * FROM income WHERE deleted_at IS NULL"
)
--- firstIncomeByUser
--- SELECT user_id, MIN(date) FROM income WHERE deleted_at IS NULL GROUP BY user_id;
-
create :: UserId -> Day -> Int -> Query Income
create userId date amount =
Query (\conn -> do
diff --git a/server/src/Persistence/Payment.hs b/server/src/Persistence/Payment.hs
index eb238d4..e01753f 100644
--- a/server/src/Persistence/Payment.hs
+++ b/server/src/Persistence/Payment.hs
@@ -1,8 +1,9 @@
module Persistence.Payment
- ( Payment(..)
+ ( count
, find
, firstPunctualDay
, listActive
+ , listActivePage
, listPunctual
, listActiveMonthlyOrderedByName
, create
@@ -54,6 +55,18 @@ instance ToRow InsertRow where
, toField (_payment_createdAt p)
]
+data Count = Count Int
+
+instance FromRow Count where
+ fromRow = Count <$> SQLite.field
+
+count :: Query Int
+count =
+ Query (\conn ->
+ (\[Count n] -> n) <$>
+ SQLite.query_ conn "SELECT COUNT(*) FROM payment WHERE deleted_at IS NULL"
+ )
+
find :: PaymentId -> Query (Maybe Payment)
find paymentId =
Query (\conn -> do
@@ -83,6 +96,16 @@ listActive =
SQLite.query_ conn "SELECT * FROM payment WHERE deleted_at IS NULL"
)
+listActivePage :: Int -> Int -> Query [Payment]
+listActivePage page perPage =
+ Query (\conn ->
+ map (\(Row p) -> p) <$>
+ SQLite.query
+ conn
+ "SELECT * FROM payment WHERE deleted_at IS NULL ORDER BY date DESC LIMIT ? OFFSET ?"
+ (perPage, (page - 1) * perPage)
+ )
+
listPunctual :: Query [Payment]
listPunctual =
Query (\conn -> do