From 5280255ddc26bceacbaf351c115530bc55034d68 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 9 Aug 2019 20:55:40 +0200 Subject: [PATCH] let the function get the time itself --- src/Main.hs | 3 +-- src/Model/Amount.hs | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index e3109a5..2e0ce12 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -184,9 +184,8 @@ userList muid ref = do productNew :: Maybe Int -> ProductSubmit -> MateHandler Int productNew (Just _) bevsub = do conn <- rsConnection <$> ask - now <- liftIO $ getCurrentTime bevid <- insertProduct bevsub conn - void $ insertNewEmptyAmount bevid now bevsub conn + void $ insertNewEmptyAmount bevid bevsub conn return bevid productNew Nothing _ = throwError $ err403 diff --git a/src/Model/Amount.hs b/src/Model/Amount.hs index 94873ff..fa9b1a8 100644 --- a/src/Model/Amount.hs +++ b/src/Model/Amount.hs @@ -56,25 +56,26 @@ amountTable = table "amount" ( insertNewEmptyAmount :: Int -- | the associated product id - -> UTCTime -- | current time -> ProductSubmit -- | submitted product data -> PGS.Connection -> MateHandler Int -insertNewEmptyAmount bevid now (ProductSubmit _ price _ _ _ _ _ _ _) conn = - fmap head $ liftIO $ runInsert_ conn $ Insert - { iTable = amountTable - , iRows = - [ - ( C.constant bevid - , C.constant now - , C.constant (0 :: Int) - , C.constant price - , C.constant False - ) - ] - , iReturning = rReturning (\(id_, _, _, _, _) -> id_) - , iOnConflict = Nothing - } +insertNewEmptyAmount bevid (ProductSubmit _ price _ _ _ _ _ _ _) conn = + liftIO $ do + now <- getCurrentTime + fmap head $ runInsert_ conn $ Insert + { iTable = amountTable + , iRows = + [ + ( C.constant bevid + , C.constant now + , C.constant (0 :: Int) + , C.constant price + , C.constant False + ) + ] + , iReturning = rReturning (\(id_, _, _, _, _) -> id_) + , iOnConflict = Nothing + } getLatestPriceByProductId :: Int -- The associated Product ID