|
@@ -1,3 +1,4 @@
|
|
|
|
+
|
|
import com.fasterxml.jackson.databind.JsonNode
|
|
import com.fasterxml.jackson.databind.JsonNode
|
|
import org.http4k.core.Body
|
|
import org.http4k.core.Body
|
|
import org.http4k.core.Method.GET
|
|
import org.http4k.core.Method.GET
|
|
@@ -10,7 +11,6 @@ import org.http4k.format.Jackson.json
|
|
import org.http4k.format.Jackson.number
|
|
import org.http4k.format.Jackson.number
|
|
import org.http4k.format.Jackson.obj
|
|
import org.http4k.format.Jackson.obj
|
|
import org.http4k.lens.Query
|
|
import org.http4k.lens.Query
|
|
-import org.http4k.routing.Route
|
|
|
|
import org.http4k.routing.bind
|
|
import org.http4k.routing.bind
|
|
import java.lang.Math.max
|
|
import java.lang.Math.max
|
|
import java.lang.Math.min
|
|
import java.lang.Math.min
|
|
@@ -34,20 +34,13 @@ object WorldRoutes {
|
|
}
|
|
}
|
|
.defaulted("queries", 1)
|
|
.defaulted("queries", 1)
|
|
|
|
|
|
- operator fun invoke(database: Database): List<Route> =
|
|
|
|
- listOf(
|
|
|
|
- queryRoute(database),
|
|
|
|
- multipleRoute(database),
|
|
|
|
- updateRoute(database)
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- private fun queryRoute(database: Database): Route = "/db" to GET bind {
|
|
|
|
|
|
+ fun queryRoute(database: Database) = "/db" bind GET to {
|
|
database.withConnection {
|
|
database.withConnection {
|
|
findWorld(it, randomWorld())
|
|
findWorld(it, randomWorld())
|
|
}?.let { Response(OK).with(jsonBody of it) } ?: Response(NOT_FOUND)
|
|
}?.let { Response(OK).with(jsonBody of it) } ?: Response(NOT_FOUND)
|
|
}
|
|
}
|
|
|
|
|
|
- private fun multipleRoute(database: Database): Route = "/queries" to GET bind {
|
|
|
|
|
|
+ fun multipleRoute(database: Database) = "/queries" bind GET to {
|
|
val worlds = database.withConnection {
|
|
val worlds = database.withConnection {
|
|
con ->
|
|
con ->
|
|
(1..numberOfQueries(it)).mapNotNull { findWorld(con, randomWorld()) }
|
|
(1..numberOfQueries(it)).mapNotNull { findWorld(con, randomWorld()) }
|
|
@@ -55,7 +48,7 @@ object WorldRoutes {
|
|
Response(OK).with(jsonBody of array(worlds))
|
|
Response(OK).with(jsonBody of array(worlds))
|
|
}
|
|
}
|
|
|
|
|
|
- private fun updateRoute(database: Database): Route = "/updates" to GET bind {
|
|
|
|
|
|
+ fun updateRoute(database: Database) = "/updates" bind GET to {
|
|
val worlds = database.withConnection {
|
|
val worlds = database.withConnection {
|
|
con ->
|
|
con ->
|
|
(1..numberOfQueries(it)).mapNotNull {
|
|
(1..numberOfQueries(it)).mapNotNull {
|