30 lines
786 B
Kotlin
30 lines
786 B
Kotlin
package web
|
|
|
|
import io.ktor.http.*
|
|
import io.ktor.server.request.*
|
|
import io.ktor.server.response.*
|
|
import io.ktor.server.routing.*
|
|
import io.ktor.server.websocket.*
|
|
import io.ktor.websocket.*
|
|
import service.TranslationServiceImpl
|
|
import service.TranslationService
|
|
|
|
fun Route.translation(TranslationService: TranslationServiceImpl) {
|
|
|
|
route("/translation") {
|
|
|
|
get {
|
|
call.respond(TranslationService.getAllTranslations())
|
|
}
|
|
|
|
get("/{id}") {
|
|
val id = call.parameters["id"]?.toInt() ?: throw IllegalStateException("Must provide id")
|
|
val Translation = TranslationService.getTranslation(id)
|
|
if (Translation == null) call.respond(HttpStatusCode.NotFound)
|
|
else call.respond(Translation)
|
|
}
|
|
|
|
}
|
|
|
|
}
|