From 2312f894090122195703a690fee50577cbddb816 Mon Sep 17 00:00:00 2001 From: Luca Rossetto Date: Wed, 10 Jul 2024 15:38:33 +0200 Subject: [PATCH] SubmissionHandler now returns ApiSubmission --- .../handler/submission/SubmissionHandler.kt | 57 ++----------------- .../evaluation/submission/ApiSubmission.kt | 6 +- .../status/SuccessfulSubmissionsStatus.kt | 7 --- .../data/model/submissions/DbSubmission.kt | 2 +- 4 files changed, 10 insertions(+), 62 deletions(-) delete mode 100644 backend/src/main/kotlin/dev/dres/api/rest/types/status/SuccessfulSubmissionsStatus.kt diff --git a/backend/src/main/kotlin/dev/dres/api/rest/handler/submission/SubmissionHandler.kt b/backend/src/main/kotlin/dev/dres/api/rest/handler/submission/SubmissionHandler.kt index c5c17a52c..339e269d3 100644 --- a/backend/src/main/kotlin/dev/dres/api/rest/handler/submission/SubmissionHandler.kt +++ b/backend/src/main/kotlin/dev/dres/api/rest/handler/submission/SubmissionHandler.kt @@ -5,11 +5,11 @@ import dev.dres.api.rest.RestApi import dev.dres.api.rest.handler.AccessManagedRestHandler import dev.dres.api.rest.handler.PostRestHandler import dev.dres.api.rest.types.evaluation.submission.ApiClientSubmission +import dev.dres.api.rest.types.evaluation.submission.ApiSubmission import dev.dres.api.rest.types.evaluation.submission.ApiVerdictStatus import dev.dres.api.rest.types.status.ErrorStatus import dev.dres.api.rest.types.status.ErrorStatusException import dev.dres.api.rest.types.status.SuccessStatus -import dev.dres.api.rest.types.status.SuccessfulSubmissionsStatus import dev.dres.api.rest.types.users.ApiRole import dev.dres.data.model.run.RunActionContext.Companion.runActionContext import dev.dres.data.model.submissions.DbSubmission @@ -32,7 +32,7 @@ import kotlinx.dnq.query.firstOrNull import kotlinx.dnq.transactional import org.slf4j.LoggerFactory -class SubmissionHandler(private val store: TransientEntityStore) : PostRestHandler, +class SubmissionHandler(private val store: TransientEntityStore) : PostRestHandler, AccessManagedRestHandler { override val permittedRoles = setOf(ApiRole.PARTICIPANT) @@ -73,13 +73,8 @@ class SubmissionHandler(private val store: TransientEntityStore) : PostRestHandl responses = [ OpenApiResponse( "200", - [OpenApiContent(SuccessfulSubmissionsStatus::class)], - description = "The submission was accepted by the server and there was a verdict" - ), - OpenApiResponse( - "202", - [OpenApiContent(SuccessfulSubmissionsStatus::class)], - description = "The submission was accepted by the server and there has not yet been a verdict available" + [OpenApiContent(ApiSubmission::class)], + description = "The submission that was received." ), OpenApiResponse("400", [OpenApiContent(ErrorStatus::class)]), OpenApiResponse("401", [OpenApiContent(ErrorStatus::class)]), @@ -92,7 +87,7 @@ class SubmissionHandler(private val store: TransientEntityStore) : PostRestHandl ], tags = ["Submission"] ) - override fun doPost(ctx: Context): SuccessfulSubmissionsStatus { + override fun doPost(ctx: Context): ApiSubmission { /* Obtain run action context and parse submission. */ val rac = ctx.runActionContext() val apiClientSubmission = try { @@ -131,47 +126,7 @@ class SubmissionHandler(private val store: TransientEntityStore) : PostRestHandl ) } - - /* Return status. */ - - var correct = 0 - var wrong = 0 - var undcidable = 0 - var indeterminate = 0 - apiSubmission.answers.map { it.status() }.forEach { - when (it) { - VerdictStatus.CORRECT -> correct++ - VerdictStatus.WRONG -> wrong++ - VerdictStatus.INDETERMINATE -> indeterminate++ - VerdictStatus.UNDECIDABLE -> undcidable++ - } - } - val max = listOf(correct, wrong, undcidable, indeterminate).max() - return when (max) { - 0 -> throw ErrorStatusException( - 500, - "No verdict information available ${apiClientSubmission.submissionId}. This is a serious bug and should be reported!", - ctx - ) - - correct -> SuccessfulSubmissionsStatus(ApiVerdictStatus.CORRECT, "Submission correct, well done!") - wrong -> SuccessfulSubmissionsStatus(ApiVerdictStatus.WRONG, "Submission wrong, try again!") - undcidable -> SuccessfulSubmissionsStatus( - ApiVerdictStatus.UNDECIDABLE, - "Submission undecidable, try again!" - ) - - indeterminate -> { - ctx.status(202) - SuccessfulSubmissionsStatus(ApiVerdictStatus.INDETERMINATE, "Submission received, awaiting verdict!") - } - - else -> throw ErrorStatusException( - 500, - "Error while calculating submission verdict for submission ${apiClientSubmission.submissionId}. This is a serious bug and should be reported!", - ctx - ) - } + return apiSubmission } } diff --git a/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/submission/ApiSubmission.kt b/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/submission/ApiSubmission.kt index 5cd3c1dd3..d1a600bea 100644 --- a/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/submission/ApiSubmission.kt +++ b/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/submission/ApiSubmission.kt @@ -21,12 +21,12 @@ data class ApiSubmission( val teamName: String, val memberName: String, override val timestamp: Long, - val answers: List = emptyList() + val answerSets: List = emptyList() ) : Submission { init { - answers.forEach { it.submission = this } + answerSets.forEach { it.submission = this } } - override fun answerSets(): Sequence = answers.asSequence() + override fun answerSets(): Sequence = answerSets.asSequence() } \ No newline at end of file diff --git a/backend/src/main/kotlin/dev/dres/api/rest/types/status/SuccessfulSubmissionsStatus.kt b/backend/src/main/kotlin/dev/dres/api/rest/types/status/SuccessfulSubmissionsStatus.kt deleted file mode 100644 index 62c74310b..000000000 --- a/backend/src/main/kotlin/dev/dres/api/rest/types/status/SuccessfulSubmissionsStatus.kt +++ /dev/null @@ -1,7 +0,0 @@ -package dev.dres.api.rest.types.status - -import dev.dres.api.rest.types.evaluation.submission.ApiVerdictStatus -import kotlinx.serialization.Serializable - -@Serializable -data class SuccessfulSubmissionsStatus(val submission: ApiVerdictStatus, val description: String) : AbstractStatus(status = true) diff --git a/backend/src/main/kotlin/dev/dres/data/model/submissions/DbSubmission.kt b/backend/src/main/kotlin/dev/dres/data/model/submissions/DbSubmission.kt index 12bae742d..0e3f69153 100644 --- a/backend/src/main/kotlin/dev/dres/data/model/submissions/DbSubmission.kt +++ b/backend/src/main/kotlin/dev/dres/data/model/submissions/DbSubmission.kt @@ -72,6 +72,6 @@ class DbSubmission(entity: Entity) : PersistentEntity(entity), Submission { memberId = this.user.id, memberName = this.user.username, timestamp = this.timestamp, - answers = this.answerSets.asSequence().map { it.toApi(blind) }.toList() + answerSets = this.answerSets.asSequence().map { it.toApi(blind) }.toList() ) }