Skip to content

Commit

Permalink
adjust routes fix things etc
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesbraun committed Mar 23, 2023
1 parent ef76314 commit 66fc90a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/lu/gbraun/geo_exporter/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.ktor.server.application.*
import io.ktor.server.http.content.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import lu.gbraun.geo_exporter.controllers.stopRoutes
import lu.gbraun.geo_exporter.controllers.pointRoutes


fun Application.configureRoutes() {
Expand All @@ -15,7 +15,7 @@ fun Application.configureRoutes() {
call.respondRedirect("/index.html")
}
polygonRoutes()
stopRoutes()
pointRoutes()
mapRoutes()
static("/") {
resources("static")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import lu.gbraun.geo_exporter.entities.query.QOsmPolygon
import lu.gbraun.geo_exporter.mappers.RegionMapper

fun Route.polygonRoutes() {
get("/polygons/search/{search}") {
val search = call.parameters["search"] ?: ""
get("/polygons/search") {
val search = call.request.queryParameters["query"] ?: ""
val polygons = findPolygonsByName(search)
call.respond(polygons.map(RegionMapper.INSTANCE::mapOsmPoly))
}
get("/polygons/search/{query}") {
val search = call.parameters["query"] ?: ""
val polygons = findPolygonsByName(search)
call.respond(polygons.map(RegionMapper.INSTANCE::mapOsmPoly))
}
Expand All @@ -30,6 +35,7 @@ fun Route.polygonRoutes() {
}

private suspend fun findPolygonsByName(search: String): MutableList<OsmPolygon> {
require(search.length >= 3) { "Search query needs to be at least 3 characters." }
return withContext(Dispatchers.IO) {
val query = QOsmPolygon()
.or()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ import kotlinx.coroutines.withContext
import lu.gbraun.geo_exporter.entities.OsmPoint
import lu.gbraun.geo_exporter.mappers.PointMapper

fun Route.stopRoutes() {
get("/stops/bus_stops/{region}") {
fun Route.pointRoutes() {
get("/points/bus_stops") {
val region = requireNotNull(
call.request.queryParameters["region"]?.toIntOrNull()
)
val stops = getBusStopsInRegion(region)
val dtos = stops.map(PointMapper.INSTANCE::mapOsmPoint)
call.respond(dtos)
}
get("/points/bus_stops/{region}") {
val region = requireNotNull(call.parameters["region"]?.toIntOrNull())
val stops = getBusStopsInRegion(region)
val dtos = stops.map(PointMapper.INSTANCE::mapOsmPoint)
Expand All @@ -33,7 +41,7 @@ private suspend fun getBusStopsInRegion(regionId: Int) = withContext(Dispatchers
""".trimIndent()
)
.columnMapping("name", "name")
.columnMapping("way", "way")
.columnMapping("way", "point")
.columnMapping("id", "id")
.create()

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/lu/gbraun/geo_exporter/dto/OsmPointDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import org.geojson.Point
data class OsmPointDto(
var id: Long? = null,
var name: String? = null,
var way: Point? = null,
var point: Point? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class OsmPoint {
@Column(name = "osm_id")
var id: Long? = null
var name: String? = null
var way: Point? = null
var point: Point? = null
}

0 comments on commit 66fc90a

Please sign in to comment.