Add challenge-info endpoint
This commit is contained in:
parent
9a681701e5
commit
bb28d2c590
@ -154,6 +154,7 @@ instance Yesod App where
|
||||
isAuthorized (QueryResultsR _) _ = regularAuthorization
|
||||
isAuthorized ListChallengesR _ = regularAuthorization
|
||||
isAuthorized ListChallengesJsonR _ = regularAuthorization
|
||||
isAuthorized (ChallengeInfoJsonR _) _ = regularAuthorization
|
||||
isAuthorized (LeaderboardJsonR _) _ = regularAuthorization
|
||||
isAuthorized (ViewVariantR _ ) _ = regularAuthorization
|
||||
isAuthorized (ViewVariantTestR _ _) _ = regularAuthorization
|
||||
|
@ -22,13 +22,26 @@ declareListChallengesSwagger :: Declare (Definitions Schema) Swagger
|
||||
declareListChallengesSwagger = do
|
||||
-- param schemas
|
||||
listChallengesResponse <- declareResponse (Proxy :: Proxy [Entity Challenge])
|
||||
challengeInfoResponse <- declareResponse (Proxy :: Proxy (Entity Challenge))
|
||||
let challengeNameSchema = toParamSchema (Proxy :: Proxy String)
|
||||
|
||||
return $ mempty
|
||||
& paths .~
|
||||
[ ("/api/list-challenges", mempty & get ?~ (mempty
|
||||
& produces ?~ MimeList ["application/json"]
|
||||
& description ?~ "Returns the list of all challenges"
|
||||
& at 200 ?~ Inline listChallengesResponse))
|
||||
& at 200 ?~ Inline listChallengesResponse)),
|
||||
("/api/challenge-info/{challengeName}",
|
||||
mempty & get ?~ (mempty
|
||||
& parameters .~ [ Inline $ mempty
|
||||
& name .~ "challengeName"
|
||||
& required ?~ True
|
||||
& schema .~ ParamOther (mempty
|
||||
& in_ .~ ParamPath
|
||||
& paramSchema .~ challengeNameSchema) ]
|
||||
& produces ?~ MimeList ["application/json"]
|
||||
& description ?~ "Returns metadata for a specific challenge"
|
||||
& at 200 ?~ Inline challengeInfoResponse))
|
||||
]
|
||||
|
||||
listChallengesApi :: Swagger
|
||||
@ -93,6 +106,11 @@ getChallenges filterExpr = runDB $ selectList filterExpr [Desc ChallengeStarred,
|
||||
listChallengesCore :: [Entity Challenge] -> Widget
|
||||
listChallengesCore challenges = $(widgetFile "list-challenges-core")
|
||||
|
||||
getChallengeInfoJsonR :: Text -> Handler Value
|
||||
getChallengeInfoJsonR challengeName = do
|
||||
entCh <- runDB $ getBy404 $ UniqueName challengeName
|
||||
return $ toJSON entCh
|
||||
|
||||
getChallengeImageR :: ChallengeId -> Handler Html
|
||||
getChallengeImageR challengeId = do
|
||||
challenge <- runDB $ get404 challengeId
|
||||
|
@ -21,6 +21,7 @@
|
||||
/api/challenge-readme/#Text/markdown ChallengeReadmeInMarkdownR GET
|
||||
/api/challenge-image/#ChallengeId ChallengeImageR GET
|
||||
/api/query/#Text QueryJsonR GET
|
||||
/api/challenge-info/#Text ChallengeInfoJsonR GET
|
||||
/list-archived-challenges ListArchivedChallengesR GET
|
||||
|
||||
/challenge/#Text ShowChallengeR GET
|
||||
|
Loading…
Reference in New Issue
Block a user