Added initial files

This commit is contained in:
2025-08-11 17:03:12 -04:00
parent a38c4059d9
commit 285585b053
6 changed files with 186 additions and 0 deletions

View 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!")
}
}
}

View 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?")
}
}
}
}

View 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}") {
}
}
}

View 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() {}
}

View 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() {}
}

View 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() {}
}