From 5ba35c5648951a1a1dac99cf00794364699261f4 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 11 Sep 2019 04:03:25 +0200 Subject: [PATCH] implement refined product select --- src/Model/Product.hs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Model/Product.hs b/src/Model/Product.hs index ceeaa14..8dc2ab5 100644 --- a/src/Model/Product.hs +++ b/src/Model/Product.hs @@ -101,11 +101,20 @@ productOverviewSelect :: ProductRefine -> PGS.Connection -> MateHandler [ProductOverview] -productOverviewSelect conn = do +productOverviewSelect refine conn = do prods <- liftIO $ runSelect conn ( proc () -> do - (i1, i2, i6, i7, i8, i9, i11, i12, i13) <- queryTable productTable -< () - returnA -< (i1, i2, i6, i7, i8, i9, i11, i12, i13) + (pid, i2, i6, i7, i8, i9, i11, i12, i13) <- queryTable productTable -< () + (a1, a2, a3, a4, a5) <- + limit 1 ( + orderBy (desc (\(_, ts, _, _, _) -> ts)) (queryTable amountTable)) + -< () + restrict -< a1 .== pid + restrict -< case refine of + AllProducts -> C.constant True + AvailableProducts -> a3 ./= C.constant (0 :: Int) + DepletedProducts -> a3 .== C.constant (0 :: Int) + returnA -< (pid, i2, i6, i7, i8, i9, i11, i12, i13) ) :: MateHandler [ ( Int , T.Text