Added initial files
This commit is contained in:
36
src/main/kotlin/routes/LibraryRoutes.kt
Normal file
36
src/main/kotlin/routes/LibraryRoutes.kt
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package codes.kalar.routes
|
||||||
|
|
||||||
|
import codes.kalar.model.Library
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.request.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
import java.sql.Connection
|
||||||
|
|
||||||
|
fun Application.configureLibraryRoutes(dbConnection: Connection) {
|
||||||
|
|
||||||
|
routing {
|
||||||
|
get("/libraries") {
|
||||||
|
call.respondText("Libraries are neat!")
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/libraries/{libraryId}/items/{itemId}") {
|
||||||
|
call.respondText("You asked for ${call.parameters["itemId"]} from ${call.parameters["libraryId"]}")
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/libraries") {
|
||||||
|
val library = call.receive<Library>()
|
||||||
|
call.respondText("${library.name} is posted")
|
||||||
|
}
|
||||||
|
|
||||||
|
patch("/libraries") {
|
||||||
|
val library = call.receive<Library>()
|
||||||
|
call.respondText("${library.name} is patched")
|
||||||
|
}
|
||||||
|
|
||||||
|
delete("/libraries") {
|
||||||
|
call.respondText("We hate to see you go!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
41
src/main/kotlin/routes/PatronRoutes.kt
Normal file
41
src/main/kotlin/routes/PatronRoutes.kt
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package codes.kalar.routes
|
||||||
|
|
||||||
|
import codes.kalar.model.Patron
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.request.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
import java.sql.Connection
|
||||||
|
|
||||||
|
fun Application.configurePatronRoutes(dbConnection: Connection) {
|
||||||
|
|
||||||
|
routing {
|
||||||
|
get("/patron") {
|
||||||
|
if (call.request.queryParameters["patron"] == null) {
|
||||||
|
call.respond(HttpStatusCode.BadRequest, "Invalid parameters")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
call.respondText("Hello, ${call.request.queryParameters["patron"]}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/patron") {
|
||||||
|
val patron = call.receive<Patron>()
|
||||||
|
call.respondText("${patron.name} is posted")
|
||||||
|
}
|
||||||
|
|
||||||
|
patch("/patron") {
|
||||||
|
val patron = call.receive<Patron>()
|
||||||
|
call.respondText("${patron.name} is patched")
|
||||||
|
}
|
||||||
|
|
||||||
|
delete("/patron") {
|
||||||
|
if (call.request.queryParameters["id"] == null) {
|
||||||
|
call.respond(HttpStatusCode.BadRequest, "Invalid parameters")
|
||||||
|
} else {
|
||||||
|
call.respondText("Do you have permissions?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/main/kotlin/routes/StaffRoutes.kt
Normal file
31
src/main/kotlin/routes/StaffRoutes.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package codes.kalar.routes
|
||||||
|
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
import java.sql.Connection
|
||||||
|
|
||||||
|
fun Application.configureStaffRoutes(dbConnection: Connection) {
|
||||||
|
|
||||||
|
routing {
|
||||||
|
get("/staff") {
|
||||||
|
call.respondText("You better have sent a body")
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/staff/{id}") {
|
||||||
|
call.respondText(call.parameters["id"]!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/staff") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
patch("/staff") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
delete("/staff/{id}") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/main/kotlin/service/LibraryService.kt
Normal file
26
src/main/kotlin/service/LibraryService.kt
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package codes.kalar.service
|
||||||
|
|
||||||
|
import codes.kalar.exception.DbElementInsertionException
|
||||||
|
import codes.kalar.exception.DbElementNotFoundException
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.sql.*
|
||||||
|
|
||||||
|
class LibraryService(private val connection: Connection) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val SELECT_LIBRARY_BY_ID = ""
|
||||||
|
private const val INSERT_LIBRARY = ""
|
||||||
|
private const val UPDATE_LIBRARY_BY_ID = ""
|
||||||
|
// In the event are "deleted" erroneously, having a flag set instead of actually removing the entry allows
|
||||||
|
// for quick reversal.
|
||||||
|
private const val ARCHIVE_LIBRARY_BY_ID = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun create() {}
|
||||||
|
|
||||||
|
suspend fun read() {}
|
||||||
|
|
||||||
|
suspend fun update() {}
|
||||||
|
|
||||||
|
suspend fun delete() {}
|
||||||
|
}
|
||||||
26
src/main/kotlin/service/PartonService.kt
Normal file
26
src/main/kotlin/service/PartonService.kt
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package codes.kalar.service
|
||||||
|
|
||||||
|
import codes.kalar.exception.DbElementInsertionException
|
||||||
|
import codes.kalar.exception.DbElementNotFoundException
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.sql.*
|
||||||
|
|
||||||
|
class PartonService(private val connection: Connection) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val SELECT_PATRON_BY_ = ""
|
||||||
|
private const val INSERT_PATRON = ""
|
||||||
|
private const val UPDATE_PATRON_BY_ID = ""
|
||||||
|
// In the event are "deleted" erroneously, having a flag set instead of actually removing the entry allows
|
||||||
|
// for quick reversal.
|
||||||
|
private const val ARCHIVE_PATRON_BY_ID = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun create() {}
|
||||||
|
|
||||||
|
suspend fun read() {}
|
||||||
|
|
||||||
|
suspend fun update() {}
|
||||||
|
|
||||||
|
suspend fun delete() {}
|
||||||
|
}
|
||||||
26
src/main/kotlin/service/StaffService.kt
Normal file
26
src/main/kotlin/service/StaffService.kt
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package codes.kalar.service
|
||||||
|
|
||||||
|
import codes.kalar.exception.DbElementInsertionException
|
||||||
|
import codes.kalar.exception.DbElementNotFoundException
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.sql.Connection
|
||||||
|
|
||||||
|
class StaffService(private val connection: Connection) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val SELECT_STAFF_BY_ID = ""
|
||||||
|
private const val INSERT_STAFF = ""
|
||||||
|
private const val UPDATE_STAFF_BY_ID = ""
|
||||||
|
// In the event are "deleted" erroneously, having a flag set instead of actually removing the entry allows
|
||||||
|
// for quick reversal.
|
||||||
|
private const val ARCHIVE_STAFF_BY_ID = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun create() {}
|
||||||
|
|
||||||
|
suspend fun read() {}
|
||||||
|
|
||||||
|
suspend fun update() {}
|
||||||
|
|
||||||
|
suspend fun delete() {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user