Introduce challenge as competitions

This commit is contained in:
Filip Gralinski 2021-03-22 08:19:47 +01:00
parent eae31a893d
commit 09aecfb76d
3 changed files with 15 additions and 7 deletions

View File

@ -329,7 +329,8 @@ addChallenge name publicRepoId privateRepoId deadline chan = do
challengeStarred=False,
challengeArchived=Just False,
challengeVersion=commit,
challengeSensitive=Just False }
challengeSensitive=Just False,
challengeIsCompetition=Just False}
_ <- runDB $ insert $ Version {
versionChallenge=Just challengeId,

View File

@ -139,10 +139,8 @@ instance ToSchema LeaderboardView where
getLeaderboardJsonR :: Text -> Handler Value
getLeaderboardJsonR challengeName = do
app <- getYesod
let leaderboardStyle = appLeaderboardStyle $ appSettings app
Entity challengeId _ <- runDB $ getBy404 $ UniqueName challengeName
Entity challengeId challenge <- runDB $ getBy404 $ UniqueName challengeName
leaderboardStyle <- determineLeaderboardStyle challenge
(leaderboard, (_, tests)) <- getLeaderboardEntries 1 leaderboardStyle challengeId
return $ toJSON $ LeaderboardView {
leaderboardViewTests = tests,
@ -192,12 +190,19 @@ toLeaderboardEntryView tests entry = LeaderboardEntryView {
map (convertEvaluationToView (leaderboardEvaluationMap entry)) tests
}
determineLeaderboardStyle :: Challenge -> Handler LeaderboardStyle
determineLeaderboardStyle challenge = do
app <- getYesod
let leaderboardStyle = appLeaderboardStyle $ appSettings app
return $ case challengeIsCompetition challenge of
Just True -> BySubmitter
_ -> leaderboardStyle
getShowChallengeR :: Text -> Handler Html
getShowChallengeR challengeName = do
app <- getYesod
let leaderboardStyle = appLeaderboardStyle $ appSettings app
challengeEnt@(Entity challengeId challenge) <- runDB $ getBy404 $ UniqueName challengeName
leaderboardStyle <- determineLeaderboardStyle challenge
isHealthy <- isChallengeHealthy challenge

View File

@ -59,6 +59,8 @@ Challenge
archived Bool Maybe
version SHA1
sensitive Bool Maybe
-- forces BySubmitter leaderboard style
isCompetition Bool Maybe
-- challenge version
Version
-- introduced later, hence Maybe