From 4b295f44d22eff08e55409f8d51ff9ddf2e49270 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Wed, 30 Nov 2022 13:30:00 +0100 Subject: [PATCH] chore(avs): fix avs interface to botched specifications --- src/Handler/Admin/Avs.hs | 40 +++++++++++++++++++++++++++++----------- src/Handler/Utils/Avs.hs | 18 ++++++++++-------- src/Model/Types/Avs.hs | 2 +- src/Utils/Avs.hs | 8 ++++---- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/Handler/Admin/Avs.hs b/src/Handler/Admin/Avs.hs index 10704553a..c36b45493 100644 --- a/src/Handler/Admin/Avs.hs +++ b/src/Handler/Admin/Avs.hs @@ -113,7 +113,7 @@ postAdminAvsR = do ((crUsrRes, crUsrWgt), crUsrEnctype) <- runFormPost $ identifyForm FIDAvsCreateUser $ \html -> flip (renderAForm FormStandard) html $ areq textField (fslI MsgAvsCardNo) Nothing let procFormCrUsr fr = do - addMessage Info $ text2Html $ "Query: " <> tshow (toJSON fr) + -- addMessage Info $ text2Html $ "Query: " <> tshow (toJSON fr) res <- try $ upsertAvsUser fr case res of (Right (Just uid)) -> do @@ -127,17 +127,33 @@ postAdminAvsR = do mbCrUser <- formResultMaybe crUsrRes procFormCrUsr ((getLicRes, getLicWgt), getLicEnctype) <- runFormPost $ identifyForm FIDAvsQueryLicence $ \html -> - flip (renderAForm FormStandard) html $ areq intField (fslI MsgAvsPersonId) Nothing + flip (renderAForm FormStandard) html $ (,,) <$> aopt intField (fslI $ text2message "Min AvsPersonId") Nothing + <*> aopt intField (fslI $ text2message "Max AvsPersonId") Nothing + <*> aopt (selectField $ return avsLicenceOptions) (fslI MsgAvsLicence) Nothing let procFormGetLic fr = do - addMessage Info $ text2Html $ "Query: " <> tshow (toJSON (AvsPersonId fr)) - res <- try $ getLicenceByAvsId $ AvsPersonId fr + res <- avsQueryGetAllLicences case res of - (Right (Just lic)) -> - return $ Just [whamlet|

Success:

Licence #{tshow lic}|] - (Right Nothing) -> - return $ Just [whamlet|

Warning:

User not found.|] - (Left e) -> do - let msg = tshow (e :: SomeException) + (Right (AvsResponseGetLicences lics)) -> do + let flics = Set.toList $ Set.filter lfltr lics + lfltr = case fr of -- not pretty, but it'll do + (Just idmin, Just idmax, Just lic) -> \AvsPersonLicence{..} -> (avsLicenceRampLicence == lic) && (avsLicencePersonID `inBetween` (AvsPersonId idmin, AvsPersonId idmax)) + (Just idmin, Nothing, Just lic) -> \AvsPersonLicence{..} -> (avsLicenceRampLicence == lic) && (avsLicencePersonID == AvsPersonId idmin) + (Nothing , Just idmax, Just lic) -> \AvsPersonLicence{..} -> (avsLicenceRampLicence == lic) && (avsLicencePersonID == AvsPersonId idmax) + (Nothing , Nothing, Just lic) -> \AvsPersonLicence{..} -> avsLicenceRampLicence == lic + (Just idmin, Just idmax, Nothing ) -> (`inBetween` (AvsPersonId idmin, AvsPersonId idmax)) . avsLicencePersonID + (Just idmin, Nothing, Nothing ) -> (== AvsPersonId idmin) . avsLicencePersonID + (Nothing , Just idmax, Nothing ) -> (== AvsPersonId idmax) . avsLicencePersonID + (Nothing , Nothing, Nothing ) -> const True + addMessage Info $ text2Html $ "Query returned " <> tshow (length flics) <> " licences." + return $ Just [whamlet| +

Success:

+