Skip to content

Commit

Permalink
feat: Stations Routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lythium4848 committed May 6, 2024
1 parent 8f209d2 commit 7a4adaf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ fun Application.module() {
fastestDeparture()
nextDeparture()
serviceDetails()
stations()
}
}
31 changes: 31 additions & 0 deletions src/main/kotlin/Routes/Stations.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package Routes

import Stations
import io.ktor.http.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun Route.stations() {
route("/stations") {
get {
val data = Stations.getStations()
call.respond(data)
}

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

val data = Stations.getStation(crs)

data ?: return@get call.respondText(
"Station not found",
status = HttpStatusCode.NotFound
)

call.respond(data)
}
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/Stations.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import kotlinx.serialization.Serializable

@Serializable
data class Station(
val crs: String,
val name: String
Expand Down

0 comments on commit 7a4adaf

Please sign in to comment.