📮 Adds auth routing
This commit is contained in:
parent
ac0ac8dd98
commit
e8ce65fbd1
@ -1,5 +1,6 @@
|
||||
package dev.svitan.plugins
|
||||
|
||||
import dev.svitan.routes.routeAuth
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.requestvalidation.*
|
||||
@ -28,4 +29,6 @@ fun Application.configureRouting() {
|
||||
call.respond("Hello World!")
|
||||
}
|
||||
}
|
||||
|
||||
routeAuth()
|
||||
}
|
||||
|
41
backend/src/main/kotlin/routes/Auth.kt
Normal file
41
backend/src/main/kotlin/routes/Auth.kt
Normal file
@ -0,0 +1,41 @@
|
||||
package dev.svitan.routes
|
||||
|
||||
import dev.svitan.schemas.AuthService
|
||||
import dev.svitan.schemas.NewAuthDTO
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.auth.authentication
|
||||
import io.ktor.server.plugins.NotFoundException
|
||||
import io.ktor.server.request.receive
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.*
|
||||
import java.util.UUID
|
||||
|
||||
fun Application.routeAuth() {
|
||||
routing {
|
||||
authentication {
|
||||
get("/auth") {
|
||||
call.respond(AuthService.readAll())
|
||||
}
|
||||
|
||||
put("/auth") {
|
||||
val auth = call.receive<NewAuthDTO>()
|
||||
call.respond(HttpStatusCode.Created, AuthService.create(auth))
|
||||
}
|
||||
|
||||
get("/auth/{id}") {
|
||||
val idRaw = call.parameters["id"] ?: throw IllegalArgumentException("Invalid id")
|
||||
val id = UUID.fromString(idRaw)
|
||||
val auth = AuthService.read(id) ?: throw NotFoundException()
|
||||
call.respond(auth)
|
||||
}
|
||||
|
||||
delete("/auth/{id}") {
|
||||
val idRaw = call.parameters["id"] ?: throw IllegalArgumentException("Invalid id")
|
||||
val id = UUID.fromString(idRaw)
|
||||
AuthService.delete(id)
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user