Skip to content

Commit 167fedb

Browse files
giacomoaccursiandrea-acampora
authored andcommitted
chore: use run method to respond to the request
1 parent 7e401d2 commit 167fedb

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/main/kotlin/infrastructure/api/handlers/SurgeryReportsArchiveHandler.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package infrastructure.api.handlers
1111
import application.presenter.api.report.toSurgeryReportEntryDto
1212
import application.service.SurgeryReportService.SurgeryReportArchiveService
1313
import infrastructure.provider.Provider
14+
import io.netty.handler.codec.http.HttpResponseStatus
1415
import io.vertx.core.Handler
1516
import io.vertx.ext.web.RoutingContext
1617
import kotlinx.serialization.encodeToString
@@ -24,18 +25,14 @@ class SurgeryReportsArchiveHandler(
2425
) : Handler<RoutingContext> {
2526

2627
override fun handle(routingContext: RoutingContext) {
27-
SurgeryReportArchiveService(provider.webClient).execute().onComplete {
28-
routingContext
29-
.response()
30-
.end(
31-
Json.encodeToString(
32-
it.map { list ->
33-
list.map { sr ->
34-
sr.toSurgeryReportEntryDto()
35-
}
36-
}.result(),
37-
),
28+
SurgeryReportArchiveService(provider.webClient).execute().onSuccess { reports ->
29+
reports.map { report ->
30+
report.toSurgeryReportEntryDto()
31+
}.run {
32+
routingContext.response().setStatusCode(HttpResponseStatus.OK.code()).end(
33+
Json.encodeToString(this),
3834
)
35+
}
3936
}
4037
}
4138
}

0 commit comments

Comments
 (0)