chore(avs): connect avs form with server request
This commit is contained in:
parent
27b4529c17
commit
5b56017683
@ -2,4 +2,5 @@ AvsCardNo: Ausweiskartennummer
|
|||||||
AvsFirstName: Vorname
|
AvsFirstName: Vorname
|
||||||
AvsLastName: Nachname
|
AvsLastName: Nachname
|
||||||
AvsInternalPersonalNo: Personalnummer (nur Fraport AG)
|
AvsInternalPersonalNo: Personalnummer (nur Fraport AG)
|
||||||
AvsVersionNo: Versionsnummer
|
AvsVersionNo: Versionsnummer
|
||||||
|
AvsQueryEmpty: Bitte mindestens ein Anfragefeld ausfüllen!
|
||||||
@ -2,4 +2,5 @@ AvsCardNo: Card number
|
|||||||
AvsFirstName: First name
|
AvsFirstName: First name
|
||||||
AvsLastName: Last name
|
AvsLastName: Last name
|
||||||
AvsInternalPersonalNo: Personnel number (Fraport AG only)
|
AvsInternalPersonalNo: Personnel number (Fraport AG only)
|
||||||
AvsVersionNo: Version number
|
AvsVersionNo: Version number
|
||||||
|
AvsQueryEmpty: At least one query field must be filled!
|
||||||
@ -4,13 +4,16 @@ module Handler.Admin.Avs
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
|
import qualified Control.Monad.State.Class as State
|
||||||
|
-- import Data.Aeson (encode)
|
||||||
|
|
||||||
import Handler.Utils
|
import Handler.Utils
|
||||||
import Handler.Utils.Servant.Avs
|
import Handler.Utils.Servant.Avs
|
||||||
|
|
||||||
makeAvsForm :: Maybe AvsPersonQuery -> Form AvsPersonQuery
|
|
||||||
-- makeAvsForm tmpl = identifyForm FIDavsPersonQuery $ \html ->
|
|
||||||
makeAvsForm tmpl html =
|
makeAvsPersonForm :: Maybe AvsPersonQuery -> Form AvsPersonQuery
|
||||||
|
makeAvsPersonForm tmpl = identifyForm FIDAvsPersonQuery . validateForm validateAvsPersonQuery $ \html ->
|
||||||
flip (renderAForm FormStandard) html $ AvsPersonQuery
|
flip (renderAForm FormStandard) html $ AvsPersonQuery
|
||||||
<$> aopt textField (fslI MsgAvsCardNo) (avsPersonQueryCardNo <$> tmpl)
|
<$> aopt textField (fslI MsgAvsCardNo) (avsPersonQueryCardNo <$> tmpl)
|
||||||
<*> aopt textField (fslI MsgAvsFirstName) (avsPersonQueryFirstName <$> tmpl)
|
<*> aopt textField (fslI MsgAvsFirstName) (avsPersonQueryFirstName <$> tmpl)
|
||||||
@ -18,20 +21,55 @@ makeAvsForm tmpl html =
|
|||||||
<*> aopt textField (fslI MsgAvsInternalPersonalNo) (avsPersonQueryInternalPersonalNo <$> tmpl)
|
<*> aopt textField (fslI MsgAvsInternalPersonalNo) (avsPersonQueryInternalPersonalNo <$> tmpl)
|
||||||
<*> aopt textField (fslI MsgAvsVersionNo) (avsPersonQueryVersionNo <$> tmpl)
|
<*> aopt textField (fslI MsgAvsVersionNo) (avsPersonQueryVersionNo <$> tmpl)
|
||||||
|
|
||||||
|
validateAvsPersonQuery :: FormValidator AvsPersonQuery Handler ()
|
||||||
|
validateAvsPersonQuery = do
|
||||||
|
AvsPersonQuery{..} <- State.get
|
||||||
|
guardValidation MsgAvsQueryEmpty $
|
||||||
|
is _Just avsPersonQueryCardNo ||
|
||||||
|
is _Just avsPersonQueryFirstName ||
|
||||||
|
is _Just avsPersonQueryLastName ||
|
||||||
|
is _Just avsPersonQueryInternalPersonalNo ||
|
||||||
|
is _Just avsPersonQueryVersionNo
|
||||||
|
|
||||||
|
{-
|
||||||
|
|
||||||
|
makeAvsForm :: Maybe AvsStatusQuery -> Form AvsStatusQuery
|
||||||
|
makeAvsForm tmpl = identifyForm FIDAvsStatusQuery . validateForm validateAvsStatusQuery $ \html ->
|
||||||
|
flip (renderAForm FormStandard) html $ AvsStatusQuery
|
||||||
|
<$> aopt textField (fslI MsgAvsCardNo) (avsPersonQueryCardNo <$> tmpl)
|
||||||
|
<*> aopt textField (fslI MsgAvsFirstName) (avsPersonQueryFirstName <$> tmpl)
|
||||||
|
<*> aopt textField (fslI MsgAvsLastName) (avsPersonQueryLastName <$> tmpl)
|
||||||
|
<*> aopt textField (fslI MsgAvsInternalPersonalNo) (avsPersonQueryInternalPersonalNo <$> tmpl)
|
||||||
|
<*> aopt textField (fslI MsgAvsVersionNo) (avsPersonQueryVersionNo <$> tmpl)
|
||||||
|
|
||||||
|
validateAvsPersonQuery :: FormValidator AvsPersonQuery Handler ()
|
||||||
|
validateAvsPersonQuery = do
|
||||||
|
AvsPersonQuery{..} <- State.get
|
||||||
|
guardValidation MsgAvsQueryEmpty $
|
||||||
|
is _Just avsPersonQueryCardNo ||
|
||||||
|
is _Just avsPersonQueryFirstName ||
|
||||||
|
is _Just avsPersonQueryLastName ||
|
||||||
|
is _Just avsPersonQueryInternalPersonalNo ||
|
||||||
|
is _Just avsPersonQueryVersionNo
|
||||||
|
-}
|
||||||
|
|
||||||
|
|
||||||
getAdminAvsR, postAdminAvsR :: Handler Html
|
getAdminAvsR, postAdminAvsR :: Handler Html
|
||||||
getAdminAvsR = postAdminAvsR
|
getAdminAvsR = postAdminAvsR
|
||||||
postAdminAvsR = do
|
postAdminAvsR = do
|
||||||
((result,widget), enctype) <- runFormPost $ makeAvsForm Nothing
|
((result,widget), enctype) <- runFormPost $ makeAvsPersonForm Nothing
|
||||||
let procForm _fr = do
|
let procForm fr = do
|
||||||
addMessage Success $ toHtml ("Form received but ignored for now. TODO."::Text)
|
res <- runAvsPersonSearch fr
|
||||||
-- TODO
|
case res of
|
||||||
return $ Just ("TODO"::Text)
|
Left err -> return $ Just err
|
||||||
|
Right jsn -> return $ Just $ tshow jsn
|
||||||
mbAnswer <- formResultMaybe result procForm
|
mbAnswer <- formResultMaybe result procForm
|
||||||
|
|
||||||
|
actionUrl <- fromMaybe AdminAvsR <$> getCurrentRoute
|
||||||
siteLayoutMsg MsgMenuAvs $ do
|
siteLayoutMsg MsgMenuAvs $ do
|
||||||
setTitleI MsgMenuAvs
|
setTitleI MsgMenuAvs
|
||||||
let formWidget = wrapForm widget def
|
let formWidget = wrapForm widget def
|
||||||
{ formAction = Just $ SomeRoute AdminAvsR
|
{ formAction = Just $ SomeRoute actionUrl
|
||||||
, formEncoding = enctype
|
, formEncoding = enctype
|
||||||
}
|
}
|
||||||
-- TODO: use i18nWidgetFile instead if this is to become permanent
|
-- TODO: use i18nWidgetFile instead if this is to become permanent
|
||||||
|
|||||||
@ -6,12 +6,14 @@
|
|||||||
module Handler.Utils.Servant.Avs where
|
module Handler.Utils.Servant.Avs where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
import Servant
|
import Servant
|
||||||
import Servant.Client
|
import Servant.Client
|
||||||
-- import Servant.API.Flatten -- requires package servant-flatten
|
-- import Servant.API.Flatten -- requires package servant-flatten
|
||||||
|
|
||||||
import qualified Network.HTTP.Client as HTTP (newManager, defaultManagerSettings)
|
import qualified Network.HTTP.Client as HTTP (newManager, defaultManagerSettings)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data AvsPersonQuery = AvsPersonQuery
|
data AvsPersonQuery = AvsPersonQuery
|
||||||
{ avsPersonQueryCardNo :: Maybe Text
|
{ avsPersonQueryCardNo :: Maybe Text
|
||||||
, avsPersonQueryFirstName :: Maybe Text
|
, avsPersonQueryFirstName :: Maybe Text
|
||||||
@ -52,6 +54,9 @@ type AVSRoute a = AVSAuth :> "FraVSMService" :> "v1" :> a
|
|||||||
type AVSPersonSearch = "PersonSearch" :> ReqBody '[JSON] AvsPersonQuery :> Post '[JSON] AvsPersonResponse
|
type AVSPersonSearch = "PersonSearch" :> ReqBody '[JSON] AvsPersonQuery :> Post '[JSON] AvsPersonResponse
|
||||||
type AVSPersonStatus = "PersonStatus" :> ReqBody '[JSON] AvsStatusQuery :> Post '[JSON] AvsStatusResponse
|
type AVSPersonStatus = "PersonStatus" :> ReqBody '[JSON] AvsStatusQuery :> Post '[JSON] AvsStatusResponse
|
||||||
|
|
||||||
|
avsApi :: Proxy AVS
|
||||||
|
avsApi = Proxy
|
||||||
|
|
||||||
{-
|
{-
|
||||||
-- Option 1:
|
-- Option 1:
|
||||||
type AVS = AVSRoute (AVSPersonSearch :<|> AVSPersonStatus)
|
type AVS = AVSRoute (AVSPersonSearch :<|> AVSPersonStatus)
|
||||||
@ -75,18 +80,30 @@ avsPersonStatus :: BasicAuthData -> AvsStatusQuery -> ClientM AvsStatusResponse
|
|||||||
(avsPersonSearch :<|> avsPersonStatus) = client avsApi
|
(avsPersonSearch :<|> avsPersonStatus) = client avsApi
|
||||||
|
|
||||||
|
|
||||||
avsApi :: Proxy AVS
|
runAvsPersonSearch :: AvsPersonQuery -> Import.Handler (Either Text AvsPersonResponse)
|
||||||
avsApi = Proxy
|
runAvsPersonSearch qry = do
|
||||||
|
manager <- getsYesod $ view _appHttpManager
|
||||||
avsServer :: BaseUrl
|
mbAvsConf <- getsYesod $ view _appAvsConf
|
||||||
avsServer = BaseUrl
|
case mbAvsConf of
|
||||||
{ baseUrlScheme = Https
|
Nothing -> return $ Left "appAvsConfig is empty, i.e. invalid AVS configuration settings."
|
||||||
, baseUrlHost = "skytest.fra.fraport.de"
|
Just avsConf -> do
|
||||||
, baseUrlPort = 80
|
-- TODO: consider using Servant.Client.Core.parseBaseUrl within Settings already at Startup!
|
||||||
, baseUrlPath = ""
|
let avsServer = BaseUrl
|
||||||
}
|
{ baseUrlScheme = Https
|
||||||
|
, baseUrlHost = avsHost avsConf
|
||||||
|
, baseUrlPort = avsPort avsConf
|
||||||
|
, baseUrlPath = ""
|
||||||
|
}
|
||||||
|
avsAuth = BasicAuthData
|
||||||
|
{ basicAuthUsername = avsUser avsConf
|
||||||
|
, basicAuthPassword = avsPass avsConf
|
||||||
|
}
|
||||||
|
avsClient = mkClientEnv manager avsServer
|
||||||
|
fullQuery = avsPersonSearch avsAuth qry
|
||||||
|
liftIO $ over _Left tshow <$> runClientM fullQuery avsClient
|
||||||
|
|
||||||
|
|
||||||
|
-- DEMO to check that it types
|
||||||
run :: IO ()
|
run :: IO ()
|
||||||
run = do
|
run = do
|
||||||
manager' <- HTTP.newManager HTTP.defaultManagerSettings
|
manager' <- HTTP.newManager HTTP.defaultManagerSettings
|
||||||
@ -95,4 +112,12 @@ run = do
|
|||||||
case res of
|
case res of
|
||||||
Left err -> putStrLn $ "Error: " ++ tshow err
|
Left err -> putStrLn $ "Error: " ++ tshow err
|
||||||
Right resp -> do
|
Right resp -> do
|
||||||
print resp
|
print resp
|
||||||
|
where
|
||||||
|
avsServer :: BaseUrl
|
||||||
|
avsServer = BaseUrl
|
||||||
|
{ baseUrlScheme = Https
|
||||||
|
, baseUrlHost = "skytest.fra.fraport.de"
|
||||||
|
, baseUrlPort = 80
|
||||||
|
, baseUrlPath = ""
|
||||||
|
}
|
||||||
|
|||||||
@ -868,6 +868,11 @@ whenIsRight (Left _) _ = return ()
|
|||||||
throwLeft :: (MonadThrow m, Exception exc) => Either exc a -> m a
|
throwLeft :: (MonadThrow m, Exception exc) => Either exc a -> m a
|
||||||
throwLeft = either throwM return
|
throwLeft = either throwM return
|
||||||
|
|
||||||
|
{- Just a reminder for Steffen:
|
||||||
|
mapLeft :: (a -> c) -> Either a b -> Either c b
|
||||||
|
mapLeft = over _Left
|
||||||
|
-}
|
||||||
|
|
||||||
---------------
|
---------------
|
||||||
-- Exception --
|
-- Exception --
|
||||||
---------------
|
---------------
|
||||||
|
|||||||
@ -295,6 +295,8 @@ data FormIdentifier
|
|||||||
| FIDTestDownload
|
| FIDTestDownload
|
||||||
| FIDAllocationRegister
|
| FIDAllocationRegister
|
||||||
| FIDAllocationNotification
|
| FIDAllocationNotification
|
||||||
|
| FIDAvsPersonQuery
|
||||||
|
| FIDAvsStatusQuery
|
||||||
deriving (Eq, Ord, Read, Show)
|
deriving (Eq, Ord, Read, Show)
|
||||||
|
|
||||||
instance PathPiece FormIdentifier where
|
instance PathPiece FormIdentifier where
|
||||||
|
|||||||
@ -3,5 +3,6 @@
|
|||||||
Abfrage:
|
Abfrage:
|
||||||
^{formWidget}
|
^{formWidget}
|
||||||
$maybe answer <- mbAnswer
|
$maybe answer <- mbAnswer
|
||||||
<p>Unverarbeitete Antwort:
|
<p>
|
||||||
|
Unverarbeitete Antwort: #
|
||||||
#{answer}
|
#{answer}
|
||||||
|
|||||||
Reference in New Issue
Block a user