Update dependencies

This commit is contained in:
Michael Bull 2022-04-15 15:16:40 +01:00
parent ea9298c8fe
commit 96a84b227b
3 changed files with 13 additions and 13 deletions

View File

@ -1,9 +1,9 @@
object Versions { object Versions {
const val dokka = "1.6.10" const val dokka = "1.6.20"
const val kotlin = "1.6.10" const val kotlin = "1.6.20"
const val kotlinBenchmark = "0.4.1" const val kotlinBenchmark = "0.4.2"
const val kotlinCoroutines = "1.6.0" const val kotlinCoroutines = "1.6.1"
const val ktor = "2.0.0-beta-1" const val ktor = "2.0.0"
const val logback = "1.2.3" const val logback = "1.2.3"
const val versionsPlugin = "0.41.0" const val versionsPlugin = "0.41.0"
} }

View File

@ -13,9 +13,9 @@ dependencies {
implementation(project(":kotlin-result")) implementation(project(":kotlin-result"))
implementation(kotlin("stdlib-jdk8")) implementation(kotlin("stdlib-jdk8"))
implementation("ch.qos.logback:logback-classic:${Versions.logback}") implementation("ch.qos.logback:logback-classic:${Versions.logback}")
implementation("io.ktor:ktor-serialization-jackson:${Versions.ktor}")
implementation("io.ktor:ktor-server-core:${Versions.ktor}") implementation("io.ktor:ktor-server-core:${Versions.ktor}")
implementation("io.ktor:ktor-server-content-negotiation:${Versions.ktor}") implementation("io.ktor:ktor-server-content-negotiation:${Versions.ktor}")
implementation("io.ktor:ktor-serialization-jackson:${Versions.ktor}")
implementation("io.ktor:ktor-server-netty:${Versions.ktor}") implementation("io.ktor:ktor-server-netty:${Versions.ktor}")
} }

View File

@ -37,7 +37,7 @@ import io.ktor.server.application.call
import io.ktor.server.application.install import io.ktor.server.application.install
import io.ktor.server.engine.embeddedServer import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty import io.ktor.server.netty.Netty
import io.ktor.server.plugins.ContentNegotiation import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.request.receive import io.ktor.server.request.receive
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.get import io.ktor.server.routing.get
@ -46,8 +46,8 @@ import io.ktor.server.routing.routing
fun main() { fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") { embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
configureRouting()
configureSerialization() configureSerialization()
configureRouting()
}.start(wait = true) }.start(wait = true)
} }
@ -73,7 +73,8 @@ fun Application.configureRouting() {
routing { routing {
get("/customers/{id}") { get("/customers/{id}") {
val (status, message) = call.parameters.readId() val (status, message) = call.parameters
.readId()
.andThen(customerService::getById) .andThen(customerService::getById)
.mapBoth(::customerToResponse, ::messageToResponse) .mapBoth(::customerToResponse, ::messageToResponse)
@ -81,7 +82,8 @@ fun Application.configureRouting() {
} }
post("/customers/{id}") { post("/customers/{id}") {
val (status, message) = call.parameters.readId() val (status, message) = call.parameters
.readId()
.andThen { customerService.save(it, call.receive()) } .andThen { customerService.save(it, call.receive()) }
.mapBoth(::eventToResponse, ::messageToResponse) .mapBoth(::eventToResponse, ::messageToResponse)
@ -95,9 +97,7 @@ fun Application.configureRouting() {
} }
private fun Parameters.readId(): Result<Long, DomainMessage> { private fun Parameters.readId(): Result<Long, DomainMessage> {
return get("id") return get("id")?.toLongOrNull().toResultOr { CustomerRequired }
?.toLongOrNull()
.toResultOr { CustomerRequired }
} }
private fun customerToResponse(customer: CustomerDto) = HttpStatusCode.OK to customer private fun customerToResponse(customer: CustomerDto) = HttpStatusCode.OK to customer