Rename BodyBuilder#bodyAndAwait to bodyValueAndAwait

This commit is contained in:
Sebastien Deleuze
2019-09-05 13:32:39 +02:00
parent 73f5d05fd9
commit 40a55b412d
3 changed files with 5 additions and 5 deletions

View File

@@ -50,7 +50,7 @@ inline fun <reified T : Any> ServerResponse.BodyBuilder.body(producer: Any): Mon
body(producer, object : ParameterizedTypeReference<T>() {}) body(producer, object : ParameterizedTypeReference<T>() {})
/** /**
* Coroutines variant of [ServerResponse.BodyBuilder.body] with an [Any] parameter. * Coroutines variant of [ServerResponse.BodyBuilder.bodyValue].
* *
* Set the body of the response to the given {@code Object} and return it. * Set the body of the response to the given {@code Object} and return it.
* This convenience method combines [body] and * This convenience method combines [body] and
@@ -60,7 +60,7 @@ inline fun <reified T : Any> ServerResponse.BodyBuilder.body(producer: Any): Mon
* @throws IllegalArgumentException if `body` is a [Publisher] or an * @throws IllegalArgumentException if `body` is a [Publisher] or an
* instance of a type supported by [org.springframework.core.ReactiveAdapterRegistry.getSharedInstance], * instance of a type supported by [org.springframework.core.ReactiveAdapterRegistry.getSharedInstance],
*/ */
suspend fun ServerResponse.BodyBuilder.bodyAndAwait(body: Any): ServerResponse = suspend fun ServerResponse.BodyBuilder.bodyValueAndAwait(body: Any): ServerResponse =
bodyValue(body).awaitSingle() bodyValue(body).awaitSingle()
/** /**

View File

@@ -69,7 +69,7 @@ class ServerResponseExtensionsTests {
val body = "foo" val body = "foo"
every { bodyBuilder.bodyValue(ofType<String>()) } returns Mono.just(response) every { bodyBuilder.bodyValue(ofType<String>()) } returns Mono.just(response)
runBlocking { runBlocking {
bodyBuilder.bodyAndAwait(body) bodyBuilder.bodyValueAndAwait(body)
} }
verify { verify {
bodyBuilder.bodyValue(ofType<String>()) bodyBuilder.bodyValue(ofType<String>())

View File

@@ -351,7 +351,7 @@ found. If it is not found, we use `switchIfEmpty(Mono<T>)` to return a 404 Not F
suspend fun getPerson(request: ServerRequest): ServerResponse { // <3> suspend fun getPerson(request: ServerRequest): ServerResponse { // <3>
val personId = request.pathVariable("id").toInt() val personId = request.pathVariable("id").toInt()
return repository.getPerson(personId)?.let { ok().contentType(APPLICATION_JSON).bodyAndAwait(it) } return repository.getPerson(personId)?.let { ok().contentType(APPLICATION_JSON).bodyValueAndAwait(it) }
?: ServerResponse.notFound().buildAndAwait() ?: ServerResponse.notFound().buildAndAwait()
} }
@@ -477,7 +477,7 @@ header:
---- ----
val route = coRouter { val route = coRouter {
(GET("/hello-world") and accept(MediaType.TEXT_PLAIN)).invoke { (GET("/hello-world") and accept(MediaType.TEXT_PLAIN)).invoke {
ServerResponse.ok().bodyAndAwait("Hello World") ServerResponse.ok().bodyValueAndAwait("Hello World")
} }
} }
---- ----