Skip to content

Commit

Permalink
feat: Route to get trains from a CRS to another
Browse files Browse the repository at this point in the history
  • Loading branch information
Lythium4848 committed May 6, 2024
1 parent 7a4adaf commit 61c86f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/main/kotlin/Routes/Departure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun Route.departure() {
)

val filterCRS = call.parameters["filterCRS"] ?: ""
val filterType = call.parameters["filterType"] ?: ""
val filterType = call.parameters["filterType"] ?: "to"
val timeOffset = call.parameters["timeOffset"]?.toIntOrNull() ?: 0
val timeWindow = call.parameters["timeWindow"]?.toIntOrNull() ?: 120

Expand All @@ -32,6 +32,32 @@ fun Route.departure() {
val data = ldbws.getDepartureBoard(10, crs, filterCRS, filterType, timeOffset, timeWindow)
call.respond(data)
}

route("/to") {
get("{crs2}") {
val fromCRS = call.parameters["crs"] ?: return@get call.respondText(
"From CRS not supplied. Please specify a From CRS",
status = HttpStatusCode.BadRequest
)

val toCRS = call.parameters["crs2"] ?: return@get call.respondText(
"To CRS not supplied. Please specify a To CRS",
status = HttpStatusCode.BadRequest
)

val timeOffset = call.parameters["timeOffset"]?.toIntOrNull() ?: 0
val timeWindow = call.parameters["timeWindow"]?.toIntOrNull() ?: 120

fromCRS.length != 3 && return@get call.respondText("From CRS must be 3 characters long.", status = HttpStatusCode.BadRequest)
toCRS.length != 3 && return@get call.respondText("To CRS must be 3 characters long.", status = HttpStatusCode.BadRequest)

Stations.getStation(crs = fromCRS) == null && return@get call.respondText("Invalid From CRS code.", status = HttpStatusCode.BadRequest)
Stations.getStation(crs = toCRS) == null && return@get call.respondText("Invalid To CRS code.", status = HttpStatusCode.BadRequest)

val data = ldbws.getDepartureBoard(10, fromCRS, toCRS, "to", timeOffset, timeWindow)
call.respond(data)
}
}
}
}
}
1 change: 0 additions & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@

<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
<logger name="org.mariadb.jdbc" level="INFO"/>
</configuration>

0 comments on commit 61c86f7

Please sign in to comment.