diff --git a/backend/src/main/kotlin/dev/dres/api/rest/handler/download/ScoreDownloadHandler.kt b/backend/src/main/kotlin/dev/dres/api/rest/handler/download/ScoreDownloadHandler.kt index 07505ff3..489b4381 100644 --- a/backend/src/main/kotlin/dev/dres/api/rest/handler/download/ScoreDownloadHandler.kt +++ b/backend/src/main/kotlin/dev/dres/api/rest/handler/download/ScoreDownloadHandler.kt @@ -18,10 +18,14 @@ import kotlinx.dnq.query.firstOrNull * @author Ralph Gasser * @version 1.0.0 */ -class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler { +class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler { override val route = "download/evaluation/{evaluationId}/scores" + override fun doGet(ctx: Context) { + //nop + } + @OpenApi( summary = "Provides a CSV download with the scores for a given evaluation.", path = "/api/v2/download/evaluation/{evaluationId}/scores", @@ -38,7 +42,7 @@ class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler { ], methods = [HttpMethod.GET] ) - override fun doGet(ctx: Context): String { + override fun get(ctx: Context) { val manager = ctx.eligibleManagerForId() val rac = ctx.runActionContext() @@ -46,14 +50,16 @@ class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler { ctx.contentType("text/csv") ctx.header("Content-Disposition", "attachment; filename=\"scores-${manager.id}.csv\"") - /* Prepare and return response. */ - return "startTime,task,group,team,score\n" + manager.tasks(rac).filter { - it.started != null - }.sortedBy { - it.started - }.flatMap { task -> - task.scorer.scores().map { "${task.started},\"${task.template.name}\",\"${task.template.taskGroup}\",\"${manager.template.teams.firstOrNull { t -> t.id == it.first }?.name ?: "???"}\",${it.third}" } - }.joinToString(separator = "\n") + /* Prepare and send response. */ + ctx.result( + "startTime,task,group,team,score\n" + manager.tasks(rac).filter { + it.started != null + }.sortedBy { + it.started + }.flatMap { task -> + task.scorer.scores() + .map { "${task.started},\"${task.template.name}\",\"${task.template.taskGroup}\",\"${manager.template.teams.firstOrNull { t -> t.id == it.first }?.name ?: "???"}\",${it.third}" } + }.joinToString(separator = "\n") + ) } - }