From 322609ec0ff5640f26bae646c114d92488981be5 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Wed, 15 Sep 2021 13:10:44 +0200 Subject: [PATCH] Add make-public end-point --- Handler/MakePublic.hs | 6 ++++++ Handler/ShowChallenge.hs | 31 ++++++++++++++++++++++++++++++- Handler/Swagger.hs | 1 + config/routes | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Handler/MakePublic.hs b/Handler/MakePublic.hs index efcc8cc..deddf60 100644 --- a/Handler/MakePublic.hs +++ b/Handler/MakePublic.hs @@ -9,6 +9,12 @@ import PersistSHA1 import Data.Text as T import Handler.Runner +import Handler.JWT + +getMakePublicJsonR :: SubmissionId -> Handler Value +getMakePublicJsonR submissionId = do + Entity userId _ <- requireAuthPossiblyByToken + runViewProgressAsynchronously $ doMakePublic userId submissionId getMakePublicR :: SubmissionId -> Handler TypedContent getMakePublicR submissionId = do diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index 9d9c552..b6dc7cd 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -18,7 +18,6 @@ import qualified Yesod.Table as Table import Control.Concurrent.Lifted (threadDelay) import Data.Time.LocalTime -import Data.Time.Clock import qualified Data.List.Utils as DLU @@ -667,6 +666,36 @@ challengeSubmissionApi = spec & definitions .~ defs (defs, spec) = runDeclare declareChallengeSubmissionSwagger mempty +declareMakePublicSwagger :: Declare (Definitions Schema) Swagger +declareMakePublicSwagger = do + -- param schemas + let idSchema = toParamSchema (Proxy :: Proxy Int) + + asyncJobResponse <- declareResponse (Proxy :: Proxy Int) + wrongSubmissionResponse <- declareResponse (Proxy :: Proxy GonitoStatus) + + return $ mempty + & paths .~ + fromList [ ("/api/make-public/{submissionId}", + mempty & DS.get ?~ (mempty + & parameters .~ [ Inline $ mempty + & name .~ "submissionId" + & required ?~ True + & schema .~ ParamOther (mempty + & in_ .~ ParamPath + & paramSchema .~ idSchema)] + & produces ?~ MimeList ["application/json"] + & description ?~ "Initiates opening a submission. Returns an asynchrous job ID." + & at 200 ?~ Inline asyncJobResponse + & at 422 ?~ Inline wrongSubmissionResponse)) + ] + +makePublicApi :: Swagger +makePublicApi = spec & definitions .~ defs + where + (defs, spec) = runDeclare declareMakePublicSwagger mempty + + data ChallangeSubmissionStatus = SubmissionOK | SubmissionWrong Text deriving (Eq, Show) diff --git a/Handler/Swagger.hs b/Handler/Swagger.hs index 29f2f36..acba8f9 100644 --- a/Handler/Swagger.hs +++ b/Handler/Swagger.hs @@ -27,6 +27,7 @@ apiDescription = generalApi <> challengeReadmeInMarkdownApi <> queryApi <> challengeSubmissionApi + <> makePublicApi <> versionInfoApi <> listTagsApi <> myTeamsApi diff --git a/config/routes b/config/routes index c12f476..d3a42c1 100644 --- a/config/routes +++ b/config/routes @@ -25,6 +25,8 @@ /api/user-info UserInfoR GET /api/add-user AddUserR GET /api/challenge-submission/#Text ChallengeSubmissionJsonR POST +/api/make-public/#SubmissionId MakePublicJsonR GET + /api/challenge-readme/#Text/markdown ChallengeReadmeInMarkdownR GET /api/challenge-img/#Text ChallengeImgR GET /api/query/#Text QueryJsonR GET