From fb29ba81140962d04f5020fc7d5c9fb7b4f5195c Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Mon, 8 Feb 2021 20:52:12 +0100 Subject: [PATCH] Add info about the image --- Handler/ListChallenges.hs | 12 +++++++++--- config/routes | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Handler/ListChallenges.hs b/Handler/ListChallenges.hs index 429d759..72d0c78 100644 --- a/Handler/ListChallenges.hs +++ b/Handler/ListChallenges.hs @@ -8,10 +8,8 @@ import Import hiding (get, fromList, Proxy) import Data.HashMap.Strict.InsOrd (fromList) import Data.Proxy -import Data.Aeson import Control.Lens hiding ((.=)) import Data.Swagger -import Data.Swagger.Lens import Data.Swagger.Declare mainCondition :: [Filter Challenge] @@ -44,13 +42,20 @@ getListChallengesJsonR = generalListChallengesJson mainCondition getListArchivedChallengesR :: Handler Html getListArchivedChallengesR = generalListChallenges [ChallengeArchived ==. Just True] +imageUrl :: Entity Challenge -> Maybe (Route App) +imageUrl (Entity challengeId challenge) = + case challengeImage challenge of + Just _ -> Just $ ChallengeImageR challengeId + Nothing -> Nothing + instance ToJSON (Entity Challenge) where - toJSON (Entity _ ch) = object + toJSON chEnt@(Entity _ ch) = object [ "name" .= challengeName ch , "title" .= challengeTitle ch , "description" .= challengeDescription ch , "starred" .= challengeStarred ch , "archived" .= challengeArchived ch + , "imageUrl" .= (("/" <>) <$> intercalate "/" <$> fst <$> renderRoute <$> imageUrl chEnt) ] instance ToSchema (Entity Challenge) where @@ -65,6 +70,7 @@ instance ToSchema (Entity Challenge) where , ("description", stringSchema) , ("starred", booleanSchema) , ("archived", booleanSchema) + , ("imageUrl", stringSchema) ] & required .~ [ "name", "title", "description", "starred", "archived" ] diff --git a/config/routes b/config/routes index c55a0cf..1ff9f76 100644 --- a/config/routes +++ b/config/routes @@ -19,7 +19,7 @@ /api/add-user AddUserR GET /api/challenge-submission/#Text ChallengeSubmissionJsonR POST /api/challenge-readme/#Text/markdown ChallengeReadmeInMarkdownR GET -/challenge-image/#ChallengeId ChallengeImageR GET +/api/challenge-image/#ChallengeId ChallengeImageR GET /list-archived-challenges ListArchivedChallengesR GET /challenge/#Text ShowChallengeR GET