fix build

This commit is contained in:
Steffen Jost 2022-09-23 12:37:25 +02:00
parent a78cf6c301
commit d75f741289
2 changed files with 29 additions and 20 deletions

View File

@ -1,4 +1,4 @@
module Handler.Utils.Avs module Handler.Utils.Avs
( -- upsertAvsUser ( -- upsertAvsUser
--, checkLicences --, checkLicences
getLicence, getLicenceDB getLicence, getLicenceDB
@ -38,41 +38,42 @@ instance Exception AvsException
-} -}
-- Do we need this? -- Do we need this?
getLicence :: UserId -> Handler (Maybe AvsLicence) -- getLicence :: UserId -> Handler (Maybe AvsLicence) -- with runDB
getLicence uid = do getLicence :: ( MonadThrow m, MonadHandler m, HandlerSite m ~ UniWorX, WithRunDB SqlReadBackend (HandlerFor UniWorX) m ) => UserId -> m (Maybe AvsLicence)
getLicence uid = do
AvsQuery{..} <- maybeThrowM AvsInterfaceUnavailable $ getsYesod $ view _appAvsQuery AvsQuery{..} <- maybeThrowM AvsInterfaceUnavailable $ getsYesod $ view _appAvsQuery
Entity _ UserAvs{..} <- maybeThrowM (AvsUserUnknown uid) $ runDB $ getBy $ UniqueUserAvsUser uid Entity _ UserAvs{..} <- maybeThrowM (AvsUserUnknown uid) $ useRunDB $ getBy $ UniqueUserAvsUser uid
AvsResponseGetLicences licences <- throwLeftM $ avsQueryGetLicences $ AvsQueryGetLicences $ Set.singleton $ AvsObjPersonId userAvsPersonId AvsResponseGetLicences licences <- throwLeftM $ avsQueryGetLicences $ AvsQueryGetLicences $ Set.singleton $ AvsObjPersonId userAvsPersonId
let ulicence = Set.lookupMax $ Set.filter ((userAvsPersonId ==) . avsLicencePersonID) licences let ulicence = Set.lookupMax $ Set.filter ((userAvsPersonId ==) . avsLicencePersonID) licences
return (avsLicenceRampLicence <$> ulicence) return (avsLicenceRampLicence <$> ulicence)
getLicenceDB :: UserId -> DB (Maybe AvsLicence) getLicenceDB :: UserId -> DB (Maybe AvsLicence)
getLicenceDB uid = do getLicenceDB uid = do
AvsQuery{..} <- maybeThrowM AvsInterfaceUnavailable $ liftHandler $ getsYesod $ view _appAvsQuery AvsQuery{..} <- maybeThrowM AvsInterfaceUnavailable $ liftHandler $ getsYesod $ view _appAvsQuery
Entity _ UserAvs{..} <- maybeThrowM (AvsUserUnknown uid) $ getBy $ UniqueUserAvsUser uid Entity _ UserAvs{..} <- maybeThrowM (AvsUserUnknown uid) $ getBy $ UniqueUserAvsUser uid
AvsResponseGetLicences licences <- throwLeftM $ avsQueryGetLicences $ AvsQueryGetLicences $ Set.singleton $ AvsObjPersonId userAvsPersonId AvsResponseGetLicences licences <- throwLeftM $ avsQueryGetLicences $ AvsQueryGetLicences $ Set.singleton $ AvsObjPersonId userAvsPersonId
let ulicence = Set.lookupMax $ Set.filter ((userAvsPersonId ==) . avsLicencePersonID) licences let ulicence = Set.lookupMax $ Set.filter ((userAvsPersonId ==) . avsLicencePersonID) licences
return (avsLicenceRampLicence <$> ulicence) return (avsLicenceRampLicence <$> ulicence)
setLicence :: UserId -> AvsLicence -> Handler () setLicence :: UserId -> AvsLicence -> DB ()
setLicence uid lic = do setLicence uid lic = do
Entity _ UserAvs{..} <- maybeThrowM (AvsUserUnknown uid) $ runDB $ getBy $ UniqueUserAvsUser uid Entity _ UserAvs{..} <- maybeThrowM (AvsUserUnknown uid) $ getBy $ UniqueUserAvsUser uid
setLicenceAvs userAvsPersonId lic setLicenceAvs userAvsPersonId lic
setLicenceAvs :: AvsPersonId -> AvsLicence -> Handler () setLicenceAvs :: AvsPersonId -> AvsLicence -> DB ()
setLicenceAvs apid lic = do setLicenceAvs apid lic = do
let req = Set.singleton $ AvsPersonLicence apid lic let req = Set.singleton $ AvsPersonLicence apid lic
setLicencesAvs req setLicencesAvs req
setLicencesAvs :: Set AvsPersonLicence -> Handler () setLicencesAvs :: Set AvsPersonLicence -> DB ()
setLicencesAvs pls = do setLicencesAvs pls = do
AvsQuery{..} <- maybeThrowM AvsInterfaceUnavailable $ getsYesod $ view _appAvsQuery AvsQuery{..} <- maybeThrowM AvsInterfaceUnavailable $ getsYesod $ view _appAvsQuery
AvsResponseSetLicences responses <- throwLeftM $ avsQuerySetLicences $ AvsQuerySetLicences pls AvsResponseSetLicences responses <- throwLeftM $ avsQuerySetLicences $ AvsQuerySetLicences pls
forM_ responses $ \AvsLicenceResponse{} -> forM_ responses $ \AvsLicenceResponse{} ->
error "CONTINUE HERE" -- TODO STUB error "CONTINUE HERE" -- TODO STUB
{- {-
-- | Retrieve all currently valid driving licences and check against our database -- | Retrieve all currently valid driving licences and check against our database
@ -88,9 +89,9 @@ checkLicences = do
-} -}
{- {-
upsertAvsUser :: AvsStatusPerson -> upsertAvsUser :: AvsStatusPerson ->
or or
upsertAvsUser :: AvsPersonId -> upsertAvsUser :: AvsPersonId ->
-} -}

View File

@ -3,6 +3,14 @@ module Utils.TypesSpec where
import TestImport import TestImport
instance Arbitrary AvsPersonId where
arbitrary = AvsPersonId <$> arbitrary
shrink (AvsPersonId x) = AvsPersonId <$> shrink x
instance Arbitrary AvsCardNo where
arbitrary = AvsCardNo <$> arbitrary
shrink (AvsCardNo x) = AvsCardNo <$> shrink x
instance Arbitrary AvsDataCardColor where instance Arbitrary AvsDataCardColor where
arbitrary = genericArbitrary arbitrary = genericArbitrary
shrink = genericShrink shrink = genericShrink