Created initial patch and delete and updated get endpoints
This commit is contained in:
@@ -33,8 +33,20 @@ fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
||||
}
|
||||
}
|
||||
|
||||
get("/libraries/{id}") {
|
||||
try {
|
||||
val id = call.pathParameters["id"]!!.toLong()
|
||||
val library = libraryService.readLibraryById(id)
|
||||
call.respond(HttpStatusCode.OK, library)
|
||||
} catch (cause: DbElementNotFoundException) {
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Unable to find Library.")
|
||||
} catch (cause: NumberFormatException) {
|
||||
call.respond(HttpStatusCode.BadRequest, "Unable to parse number format. \"${call.pathParameters["id"]}\" is not a number.")
|
||||
}
|
||||
}
|
||||
|
||||
get("/libraries/{libraryId}/items/{itemId}") {
|
||||
call.respondText("You asked for ${call.parameters["itemId"]} from ${call.parameters["libraryId"]}")
|
||||
// TODO Add search for collection_it where itemID && libraryID
|
||||
}
|
||||
|
||||
post("/libraries") {
|
||||
@@ -48,12 +60,36 @@ fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
||||
}
|
||||
|
||||
patch("/libraries") {
|
||||
val library = call.receive<Library>()
|
||||
call.respondText("${library.name} is patched")
|
||||
try {
|
||||
val library = call.receive<Library>()
|
||||
val patchedLibrary = libraryService.update(library)
|
||||
call.respond(HttpStatusCode.OK, patchedLibrary)
|
||||
} catch (cause: DbElementInsertionException) {
|
||||
log.error(cause.message)
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Unable to update Library.")
|
||||
} catch (cause: DbElementInsertionException) {
|
||||
log.error(cause.message)
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Bad Arguments")
|
||||
} catch (cause: ContentTransformationException) {
|
||||
log.error(cause.message)
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Bad Arguments")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delete("/libraries") {
|
||||
call.respondText("We hate to see you go!")
|
||||
try {
|
||||
val id = call.parameters["id"]!!.toLong()
|
||||
log.info("Deleting item with id=$id")
|
||||
libraryService.delete(id)
|
||||
call.respondText(":(", status = HttpStatusCode.OK)
|
||||
} catch (cause: DbElementNotFoundException) {
|
||||
log.error(cause.message, cause)
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Bad Arguments")
|
||||
} catch (cause: NumberFormatException) {
|
||||
log.error(cause.message, cause)
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Invalid ID format")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user