-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added handlers to request status of submissions
- Loading branch information
Showing
10 changed files
with
182 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
backend/src/main/kotlin/dev/dres/api/rest/handler/submission/SubmissionAllStatusHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package dev.dres.api.rest.handler.submission | ||
|
||
import dev.dres.api.rest.AccessManager | ||
import dev.dres.api.rest.RestApi | ||
import dev.dres.api.rest.handler.AccessManagedRestHandler | ||
import dev.dres.api.rest.handler.GetRestHandler | ||
import dev.dres.api.rest.types.evaluation.submission.ApiSubmission | ||
import dev.dres.api.rest.types.evaluation.submission.ApiSubmissionList | ||
import dev.dres.api.rest.types.status.ErrorStatus | ||
import dev.dres.api.rest.types.status.ErrorStatusException | ||
import dev.dres.api.rest.types.users.ApiRole | ||
import dev.dres.data.model.run.RunActionContext.Companion.runActionContext | ||
import io.javalin.http.Context | ||
import io.javalin.openapi.* | ||
import jetbrains.exodus.database.TransientEntityStore | ||
|
||
class SubmissionAllStatusHandler(private val store: TransientEntityStore) : GetRestHandler<ApiSubmissionList>, | ||
AccessManagedRestHandler { | ||
|
||
override val permittedRoles = setOf(ApiRole.PARTICIPANT) | ||
|
||
override val apiVersion = RestApi.LATEST_API_VERSION | ||
|
||
override val route = "submission/{evaluationId}/all" | ||
|
||
|
||
@OpenApi( | ||
summary = "Endpoint provide the information about all submissions of a team.", | ||
path = "/api/v2/submission/{evaluationId}/{submissionId}", | ||
methods = [HttpMethod.GET], | ||
operationId = OpenApiOperation.AUTO_GENERATE, | ||
pathParams = [ | ||
OpenApiParam( | ||
"evaluationId", | ||
String::class, | ||
"The ID of the evaluation the submission belongs to.", | ||
required = true | ||
), | ||
], | ||
queryParams = [ | ||
OpenApiParam("session", String::class, "Session Token") | ||
], | ||
responses = [ | ||
OpenApiResponse( | ||
"200", | ||
[OpenApiContent(ApiSubmissionList::class)], | ||
description = "The submissions for this evaluation." | ||
), | ||
OpenApiResponse("404", [OpenApiContent(ErrorStatus::class)]), | ||
], | ||
tags = ["Submission"] | ||
) | ||
override fun doGet(ctx: Context): ApiSubmissionList { | ||
|
||
val rac = ctx.runActionContext() | ||
|
||
val runManager = AccessManager.getRunManagerForUser(rac.userId).find { it.id == rac.evaluationId } | ||
?: throw ErrorStatusException(404, "Evaluation with ID '${rac.evaluationId}' could not be found.", ctx) | ||
|
||
val teamId = runManager.template.teams.singleOrNull { it.users.any { u -> u.id == rac.userId } }?.id | ||
|
||
if (teamId == null) { | ||
throw ErrorStatusException(404, "No valid team found in evaluation with ID '${rac.evaluationId}'.", ctx) | ||
} | ||
|
||
val submissions = this.store.transactional(true) { | ||
runManager.allSubmissions().asSequence().filter { it.teamId == teamId }.map { it.toApi() }.toList() | ||
} | ||
|
||
return ApiSubmissionList(submissions) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
backend/src/main/kotlin/dev/dres/api/rest/handler/submission/SubmissionStatusHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package dev.dres.api.rest.handler.submission | ||
|
||
import dev.dres.api.rest.AccessManager | ||
import dev.dres.api.rest.RestApi | ||
import dev.dres.api.rest.handler.AccessManagedRestHandler | ||
import dev.dres.api.rest.handler.GetRestHandler | ||
import dev.dres.api.rest.types.evaluation.submission.ApiSubmission | ||
import dev.dres.api.rest.types.status.ErrorStatus | ||
import dev.dres.api.rest.types.status.ErrorStatusException | ||
import dev.dres.api.rest.types.users.ApiRole | ||
import dev.dres.data.model.run.RunActionContext.Companion.runActionContext | ||
import io.javalin.http.Context | ||
import io.javalin.openapi.* | ||
import jetbrains.exodus.database.TransientEntityStore | ||
|
||
class SubmissionStatusHandler(private val store: TransientEntityStore) : GetRestHandler<ApiSubmission>, | ||
AccessManagedRestHandler { | ||
|
||
override val permittedRoles = setOf(ApiRole.PARTICIPANT) | ||
|
||
override val apiVersion = RestApi.LATEST_API_VERSION | ||
|
||
override val route = "submission/{evaluationId}/{submissionId}" | ||
|
||
|
||
@OpenApi( | ||
summary = "Endpoint provide the information about a given submission.", | ||
path = "/api/v2/submission/{evaluationId}/{submissionId}", | ||
methods = [HttpMethod.GET], | ||
operationId = OpenApiOperation.AUTO_GENERATE, | ||
pathParams = [ | ||
OpenApiParam( | ||
"evaluationId", | ||
String::class, | ||
"The ID of the evaluation the submission belongs to.", | ||
required = true | ||
), | ||
OpenApiParam( | ||
"submissionId", | ||
String::class, | ||
"The ID of the submission.", | ||
required = true | ||
), | ||
], | ||
queryParams = [ | ||
OpenApiParam("session", String::class, "Session Token") | ||
], | ||
responses = [ | ||
OpenApiResponse( | ||
"200", | ||
[OpenApiContent(ApiSubmission::class)], | ||
description = "The submission." | ||
), | ||
OpenApiResponse("404", [OpenApiContent(ErrorStatus::class)]), | ||
], | ||
tags = ["Submission"] | ||
) | ||
override fun doGet(ctx: Context): ApiSubmission { | ||
|
||
val rac = ctx.runActionContext() | ||
|
||
val runManager = AccessManager.getRunManagerForUser(rac.userId).find { it.id == rac.evaluationId } | ||
?: throw ErrorStatusException(404, "Evaluation with ID '${rac.evaluationId}' could not be found.", ctx) | ||
|
||
val submissionId = ctx.pathParam("submissionId") | ||
|
||
val submission = this.store.transactional(true) { | ||
runManager.allSubmissions().find { it.id == submissionId }?.toApi() | ||
} | ||
|
||
if (submission == null) { | ||
throw ErrorStatusException(404, "Submission with ID '${submissionId}' not found.", ctx) | ||
} | ||
|
||
val teamId = runManager.template.teams.singleOrNull { it.users.any { u -> u.id == rac.userId } }?.id | ||
|
||
if (submission.teamId != teamId) { | ||
throw ErrorStatusException(404, "No valid submission found", ctx) | ||
} | ||
|
||
return submission | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/submission/ApiSubmissionList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.dres.api.rest.types.evaluation.submission | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ApiSubmissionList(val submissions: List<ApiSubmission>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters