-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f209d2
commit 7a4adaf
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,5 +75,6 @@ fun Application.module() { | |
fastestDeparture() | ||
nextDeparture() | ||
serviceDetails() | ||
stations() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|