From 177a4303bcdda8ccececba43d85b522e104a554a Mon Sep 17 00:00:00 2001 From: Nicholas Kalar Date: Sun, 10 Aug 2025 16:25:06 -0400 Subject: [PATCH] Refactored code out --- src/main/kotlin/Routing.kt | 70 +++++++------------------------------- 1 file changed, 13 insertions(+), 57 deletions(-) diff --git a/src/main/kotlin/Routing.kt b/src/main/kotlin/Routing.kt index 548ae58..1db34b8 100644 --- a/src/main/kotlin/Routing.kt +++ b/src/main/kotlin/Routing.kt @@ -1,74 +1,30 @@ package codes.kalar -import com.auth0.jwt.JWT -import com.auth0.jwt.algorithms.Algorithm +import codes.kalar.routes.configureCollectionItemRoutes +import codes.kalar.routes.configureLibraryRoutes +import codes.kalar.routes.configurePatronRoutes +import codes.kalar.routes.configureStaffRoutes import io.ktor.http.* -import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* -import io.ktor.server.auth.* -import io.ktor.server.auth.jwt.* -import io.ktor.server.plugins.contentnegotiation.* -import io.ktor.server.plugins.defaultheaders.* -import io.ktor.server.plugins.swagger.* -import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import java.sql.Connection -import java.sql.DriverManager fun Application.configureRouting() { + val dbConnection: Connection = connectToPostgres() + + configureCollectionItemRoutes(dbConnection) + configurePatronRoutes(dbConnection) + configureLibraryRoutes(dbConnection) + configureStaffRoutes(dbConnection) + routing { get("/") { - call.respondText("Hello World!") - } - - get("/patron") { - if (call.request.queryParameters.isEmpty()) { - call.respond(HttpStatusCode.BadRequest, "Invalid parameters") - } - else { - call.respondText("Hello, ${call.request.queryParameters["patron"]}") - } - } - - post("/patron") { - call.respondText("Patron is posted") - } - - delete("/patron") { - call.respondText("Do you have permissions?") - } - - get("/libraries") { - call.respondText("Libraries are neat!") - } - - post("/libraries") { - call.respondText("Library is posted") - } - - delete("/libraries/{id}") { - call.respondText("We hate to see you go!") - } - - get("/items") { - call.respondText("I'll search for that book!") - } - - post("/items") { - call.respondText("Somebody got back from Barnes & Noble!") - } - - delete("/items/{id}") { - call.respondText(":(") - } - - get("/libraries/{libraryId}/items/{itemId}") { - call.respondText("You asked for ${call.parameters["itemId"]} from ${call.parameters["libraryId"]}") + call.respondText("Hello World!", status = HttpStatusCode.OK) } get("/authenticate") { - call.respondText(System.getenv("JWT_DOMAIN") ?: "Ain't life a bitch?") + call.respondText(System.getenv("JWT_DOMAIN") ?: "You seem to be missing something") } } }