Added Staff authentication
This commit is contained in:
@@ -42,7 +42,7 @@ fun Application.configureCollectionItemRoutes(dbConnection: Connection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticate("auth-jwt") {
|
authenticate("staff") {
|
||||||
post("/items") {
|
post("/items") {
|
||||||
try {
|
try {
|
||||||
val item = call.receive<NewCollectionItem>()
|
val item = call.receive<NewCollectionItem>()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import codes.kalar.model.NewLibrary
|
|||||||
import codes.kalar.service.LibraryService
|
import codes.kalar.service.LibraryService
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.authenticate
|
||||||
import io.ktor.server.request.*
|
import io.ktor.server.request.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
@@ -41,7 +42,10 @@ fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
|||||||
} catch (cause: DbElementNotFoundException) {
|
} catch (cause: DbElementNotFoundException) {
|
||||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Unable to find Library.")
|
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Unable to find Library.")
|
||||||
} catch (cause: NumberFormatException) {
|
} catch (cause: NumberFormatException) {
|
||||||
call.respond(HttpStatusCode.BadRequest, "Unable to parse number format. \"${call.pathParameters["id"]}\" is not a number.")
|
call.respond(
|
||||||
|
HttpStatusCode.BadRequest,
|
||||||
|
"Unable to parse number format. \"${call.pathParameters["id"]}\" is not a number."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
|||||||
// TODO Add search for collection_it where itemID && libraryID
|
// TODO Add search for collection_it where itemID && libraryID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authenticate("staff") {
|
||||||
post("/libraries") {
|
post("/libraries") {
|
||||||
val library = call.receive<NewLibrary>()
|
val library = call.receive<NewLibrary>()
|
||||||
try {
|
try {
|
||||||
@@ -71,7 +76,6 @@ fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
|||||||
log.error(cause.message)
|
log.error(cause.message)
|
||||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Bad Arguments")
|
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Bad Arguments")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete("/libraries") {
|
delete("/libraries") {
|
||||||
@@ -89,5 +93,6 @@ fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import codes.kalar.model.Patron
|
|||||||
import codes.kalar.service.PatronService
|
import codes.kalar.service.PatronService
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.authenticate
|
||||||
import io.ktor.server.request.*
|
import io.ktor.server.request.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
@@ -42,6 +43,7 @@ fun Application.configurePatronRoutes(dbConnection: Connection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authenticate("staff") {
|
||||||
post("/patron") {
|
post("/patron") {
|
||||||
try {
|
try {
|
||||||
val patron = call.receive<NewPatron>()
|
val patron = call.receive<NewPatron>()
|
||||||
@@ -53,19 +55,27 @@ fun Application.configurePatronRoutes(dbConnection: Connection) {
|
|||||||
call.respond(HttpStatusCode.BadRequest, "Bad Arguments. Must pass a valid CollectionItem object.")
|
call.respond(HttpStatusCode.BadRequest, "Bad Arguments. Must pass a valid CollectionItem object.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate("general") {
|
||||||
patch("/patron") {
|
patch("/patron") {
|
||||||
try {
|
try {
|
||||||
val patron = call.receive<Patron>()
|
val patron = call.receive<Patron>()
|
||||||
val patchedPatron = patronService.update(patron)
|
val isPatched = patronService.update(patron)
|
||||||
call.respondText("${patron.name} is patched")
|
if (isPatched) {
|
||||||
|
call.respond(HttpStatusCode.OK, "${patron.name} is patched")
|
||||||
|
} else {
|
||||||
|
call.respond(HttpStatusCode.BadRequest, "${patron.name} is not patched")
|
||||||
|
}
|
||||||
} catch (cause: DbElementInsertionException) {
|
} catch (cause: DbElementInsertionException) {
|
||||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Unable to update Patron.")
|
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Unable to update Patron.")
|
||||||
} catch (cause: ContentTransformationException) {
|
} catch (cause: ContentTransformationException) {
|
||||||
|
call.respond(HttpStatusCode.BadRequest, "Bad Arguments. Must pass a valid Patron object.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authenticate("staff") {
|
||||||
delete("/patron/{id}") {
|
delete("/patron/{id}") {
|
||||||
try {
|
try {
|
||||||
val id = call.pathParameters["id"]!!.toLong()
|
val id = call.pathParameters["id"]!!.toLong()
|
||||||
@@ -78,4 +88,5 @@ fun Application.configurePatronRoutes(dbConnection: Connection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package codes.kalar.routes
|
package codes.kalar.routes
|
||||||
|
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.authenticate
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
import java.sql.Connection
|
import java.sql.Connection
|
||||||
@@ -16,6 +17,7 @@ fun Application.configureStaffRoutes(dbConnection: Connection) {
|
|||||||
call.respondText(call.parameters["id"]!!)
|
call.respondText(call.parameters["id"]!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authenticate("staff") {
|
||||||
post("/staff") {
|
post("/staff") {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,4 +30,5 @@ fun Application.configureStaffRoutes(dbConnection: Connection) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user