Add sample JSON API for listing challenges
This commit is contained in:
parent
5b05c4441c
commit
abaaf1c301
@ -152,6 +152,7 @@ instance Yesod App where
|
||||
isAuthorized QueryFormR _ = regularAuthorization
|
||||
isAuthorized (QueryResultsR _) _ = regularAuthorization
|
||||
isAuthorized ListChallengesR _ = regularAuthorization
|
||||
isAuthorized ListChallengesJsonR _ = regularAuthorization
|
||||
isAuthorized (ViewVariantR _ ) _ = regularAuthorization
|
||||
isAuthorized (ViewVariantTestR _ _) _ = regularAuthorization
|
||||
|
||||
|
@ -2,12 +2,30 @@ module Handler.ListChallenges where
|
||||
|
||||
import Import
|
||||
|
||||
mainCondition :: [Filter Challenge]
|
||||
mainCondition = [ChallengeArchived !=. Just True]
|
||||
|
||||
getListChallengesR :: Handler Html
|
||||
getListChallengesR = generalListChallenges [ChallengeArchived !=. Just True]
|
||||
getListChallengesR = generalListChallenges mainCondition
|
||||
|
||||
getListChallengesJsonR :: Handler Value
|
||||
getListChallengesJsonR = generalListChallengesJson mainCondition
|
||||
|
||||
getListArchivedChallengesR :: Handler Html
|
||||
getListArchivedChallengesR = generalListChallenges [ChallengeArchived ==. Just True]
|
||||
|
||||
instance ToJSON (Entity Challenge) where
|
||||
toJSON (Entity _ ch) = object
|
||||
[ "link" .= ("/challenge/" <> (challengeName ch))
|
||||
, "title" .= challengeTitle ch
|
||||
, "description" .= challengeDescription ch
|
||||
]
|
||||
|
||||
generalListChallengesJson :: [Filter Challenge] -> Handler Value
|
||||
generalListChallengesJson filterExpr = do
|
||||
challenges <- getChallenges filterExpr
|
||||
return $ toJSON challenges
|
||||
|
||||
generalListChallenges :: [Filter Challenge] -> Handler Html
|
||||
generalListChallenges filterExpr = do
|
||||
challenges <- getChallenges filterExpr
|
||||
|
@ -10,6 +10,7 @@
|
||||
/view-progress/#Int ViewProgressR GET
|
||||
/open-view-progress/#Int OpenViewProgressR GET
|
||||
/list-challenges ListChallengesR GET
|
||||
/api/list-challenges ListChallengesJsonR GET
|
||||
/list-archived-challenges ListArchivedChallengesR GET
|
||||
/challenge-image/#ChallengeId ChallengeImageR GET
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user