Skip to content

Commit

Permalink
Fixed redundant string escapement in ScoreDownloadHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro committed Feb 6, 2024
1 parent d312506 commit 847daf8
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import kotlinx.dnq.query.firstOrNull
* @author Ralph Gasser
* @version 1.0.0
*/
class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler<String> {
class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler<Unit> {

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",
Expand All @@ -38,22 +42,24 @@ class ScoreDownloadHandler : AbstractDownloadHandler(), GetRestHandler<String> {
],
methods = [HttpMethod.GET]
)
override fun doGet(ctx: Context): String {
override fun get(ctx: Context) {
val manager = ctx.eligibleManagerForId<RunManager>()
val rac = ctx.runActionContext()

/* Update response header. */
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")
)
}

}

0 comments on commit 847daf8

Please sign in to comment.