Add some resources
This commit is contained in:
29
src/main/kotlin/web/TranslationResource.kt
Normal file
29
src/main/kotlin/web/TranslationResource.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user