Skip to content

Commit 6c37671

Browse files
fix: change api handler return code
1 parent 9479492 commit 6c37671

9 files changed

+31
-11
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AdaptEnvironmentHandler(private val vertx: Vertx) : Handler<RoutingContext
3838
"medical-technology-automation-requests-events",
3939
Json.encodeToString(event),
4040
)
41-
routingContext.response().setStatusCode(HttpResponseStatus.OK.code()).end()
41+
routingContext.response().setStatusCode(HttpResponseStatus.NO_CONTENT.code()).end()
4242
}
4343
}
4444
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class BlockHealthProfessionalTrackingHandler(
3636
}
3737
routingContext.response()
3838
.putHeader("content-type", "application/json")
39-
.setStatusCode(HttpResponseStatus.OK.code())
39+
.setStatusCode(
40+
if (list.isNotEmpty()) HttpResponseStatus.OK.code() else HttpResponseStatus.NO_CONTENT.code(),
41+
)
4042
.end(Json.encodeToString(block))
4143
}
4244
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CustomScenarioHandler(private val vertx: Vertx) : Handler<RoutingContext>
4040
"automation-requests-events",
4141
Json.encodeToString(event),
4242
)
43-
routingContext.response().setStatusCode(HttpResponseStatus.OK.code()).end()
43+
routingContext.response().setStatusCode(HttpResponseStatus.NO_CONTENT.code()).end()
4444
}
4545
}
4646
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ class RoomInfoHandler(
3232
provider.webClient,
3333
).execute().onSuccess { room ->
3434
routingContext.response()
35-
.setStatusCode(HttpResponseStatus.OK.code())
35+
.setStatusCode(
36+
if (room != null) HttpResponseStatus.OK.code() else HttpResponseStatus.NOT_FOUND.code(),
37+
)
3638
.putHeader("content-type", "application/json")
3739
.end(
38-
Json.encodeToString(room.toRoomDto()),
40+
Json.encodeToString(room?.toRoomDto()),
3941
)
4042
}
4143
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class StopCustomScenarioHandler(private val vertx: Vertx) : Handler<RoutingConte
3434
"stop-custom-light-events",
3535
Json.encodeToString(event),
3636
)
37-
routingContext.response().setStatusCode(HttpResponseStatus.OK.code()).end()
37+
routingContext.response().setStatusCode(HttpResponseStatus.NO_CONTENT.code()).end()
3838
}
3939
}
4040
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ class SurgeryReportInfoHandler(
3131
).execute().onSuccess { report ->
3232
routingContext
3333
.response()
34-
.setStatusCode(HttpResponseStatus.OK.code())
34+
.setStatusCode(
35+
if (report != null) HttpResponseStatus.OK.code() else HttpResponseStatus.NOT_FOUND.code(),
36+
)
3537
.putHeader("content-type", "application/json")
3638
.end(
37-
Json.encodeToJsonElement(report.toApiDto()).toString(),
39+
Json.encodeToJsonElement(report?.toApiDto()).toString(),
3840
)
3941
}
4042
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class SurgeryReportsArchiveHandler(
2929
reports.map { report ->
3030
report.toSurgeryReportEntryDto()
3131
}.run {
32-
routingContext.response().setStatusCode(HttpResponseStatus.OK.code())
32+
routingContext.response().setStatusCode(
33+
if (this.isNotEmpty()) HttpResponseStatus.OK.code() else HttpResponseStatus.NO_CONTENT.code(),
34+
)
3335
.putHeader("content-type", "application/json")
3436
.end(
3537
Json.encodeToString(this),

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import application.presenter.api.tracking.toTrackingInfoDto
1313
import application.service.TrackingService
1414
import entity.room.RoomData
1515
import infrastructure.provider.Provider
16+
import io.netty.handler.codec.http.HttpResponseStatus
1617
import io.vertx.core.CompositeFuture
1718
import io.vertx.core.Handler
1819
import io.vertx.ext.web.RoutingContext
@@ -45,9 +46,17 @@ class ZoneHealthProfessionalTrackingHandler(
4546
val preOperating = result.second.result().map { hp ->
4647
hp.result().toTrackingInfoDto()
4748
}
49+
val finalList = operating + preOperating
4850
routingContext.response()
4951
.putHeader("content-type", "application/json")
50-
.end(Json.encodeToString(operating + preOperating))
52+
.setStatusCode(
53+
if (finalList.isNotEmpty()) {
54+
HttpResponseStatus.OK.code()
55+
} else {
56+
HttpResponseStatus.NO_CONTENT.code()
57+
},
58+
)
59+
.end(Json.encodeToString(finalList))
5160
}
5261
}
5362
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class ZonesHandler(
4141
}?.id?.id,
4242
)
4343
}.run {
44-
routingContext.response().setStatusCode(HttpResponseStatus.OK.code())
44+
routingContext.response()
45+
.setStatusCode(
46+
if (this.isEmpty()) HttpResponseStatus.OK.code() else HttpResponseStatus.NO_CONTENT.code(),
47+
)
4548
.putHeader("content-type", "application/json")
4649
.end(
4750
Json.encodeToString(this),

0 commit comments

Comments
 (0)