Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Readd question retrieval.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jan 15, 2022
1 parent c2d1c49 commit 0bc4e06
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions server/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ data class Submission(
val language: Question.Language,
)

@JsonClass(generateAdapter = true)
data class QuestionDescription(
val path: String,
val name: String,
val version: String,
val description: String,
val author: String,
val packageName: String,
val starter: String?
)

private val serverStarted = Instant.now()

val versionString = run {
Expand Down Expand Up @@ -176,6 +187,39 @@ fun Application.questioner() {
}
}
}
get("/question/java/{path}") {
val path = call.parameters["path"] ?: return@get call.respond(HttpStatusCode.BadRequest)
val question = Questions.load(path) ?: return@get call.respond(HttpStatusCode.NotFound)
call.respond(
QuestionDescription(
path,
question.name,
question.metadata.version,
question.metadata.javaDescription,
question.metadata.author,
question.metadata.packageName,
question.detemplatedJavaStarter,
)
)
}
get("/question/kotlin/{path}") {
val path = call.parameters["path"] ?: return@get call.respond(HttpStatusCode.BadRequest)
val question = Questions.load(path) ?: return@get call.respond(HttpStatusCode.NotFound)
if (!question.hasKotlin) {
return@get call.respond(HttpStatusCode.NotFound)
}
call.respond(
QuestionDescription(
path,
question.name,
question.metadata.version,
question.metadata.kotlinDescription!!,
question.metadata.author,
question.metadata.packageName,
starter = question.detemplatedKotlinStarter
)
)
}
}
}

Expand Down

0 comments on commit 0bc4e06

Please sign in to comment.