From b97ad942495352c3fc1e0c820cfba82a9693ac7a Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 27 Oct 2019 20:26:29 +0100 Subject: WIP Set up server side paging for incomes --- server/src/Controller/Income.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'server/src/Controller') diff --git a/server/src/Controller/Income.hs b/server/src/Controller/Income.hs index 236e032..3272cbf 100644 --- a/server/src/Controller/Income.hs +++ b/server/src/Controller/Income.hs @@ -1,5 +1,6 @@ module Controller.Income ( list + , listv2 , create , edit , delete @@ -12,7 +13,7 @@ import Web.Scotty hiding (delete) import Common.Model (CreateIncomeForm (..), EditIncomeForm (..), IncomeId, - User (..)) + IncomesAndCount (..), User (..)) import qualified Controller.Helper as ControllerHelper import Model.CreateIncome (CreateIncome (..)) @@ -28,6 +29,16 @@ list = (liftIO . Query.run $ IncomePersistence.list) >>= json ) +listv2 :: Int -> Int -> ActionM () +listv2 page perPage = + Secure.loggedAction (\_ -> + (liftIO . Query.run $ do + count <- IncomePersistence.count + incomes <- IncomePersistence.listv2 page perPage + return $ IncomesAndCount incomes count + ) >>= json + ) + create :: CreateIncomeForm -> ActionM () create form = Secure.loggedAction (\user -> -- cgit v1.2.3