Skip to content

Commit 9104513

Browse files
refactor: reduce cognitive complexity in medical technology post and get api
1 parent 996b65b commit 9104513

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

Diff for: src/main/kotlin/infrastructure/api/MedicalTechnologyApi.kt

+9-17
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ fun Application.medicalTechnologyAPI(apiPath: String, port: Int, provider: Manag
4848
provider.medicalTechnologyDigitalTwinManager,
4949
provider.medicalTechnologyDatabaseManager
5050
)
51-
).execute().apply {
52-
if (this == null) {
53-
call.respond(HttpStatusCode.Conflict)
54-
} else {
55-
call.response.header(
56-
HttpHeaders.Location,
57-
"http://localhost:$port$apiPath/medical-technologies/${medicalTechnology.id.value}"
58-
)
59-
call.respond(HttpStatusCode.Created)
60-
}
61-
}
51+
).execute()?.apply {
52+
call.response.header(
53+
HttpHeaders.Location,
54+
"http://localhost:$port$apiPath/medical-technologies/${medicalTechnology.id.value}"
55+
)
56+
call.respond(HttpStatusCode.Created)
57+
} ?: call.respond(HttpStatusCode.Conflict)
6258
}
6359
get("$apiPath/medical-technologies/{technologyId}") {
6460
MedicalTechnologyService.GetMedicalTechnology(
@@ -68,12 +64,8 @@ fun Application.medicalTechnologyAPI(apiPath: String, port: Int, provider: Manag
6864
provider.medicalTechnologyDatabaseManager
6965
),
7066
call.request.queryParameters["dateTime"]?.let { rawDateTime -> Instant.parse(rawDateTime) }
71-
).execute().apply {
72-
when (this) {
73-
null -> call.respond(HttpStatusCode.NotFound)
74-
else -> call.respond(this.toMedicalTechnologyApiDto())
75-
}
76-
}
67+
).execute()?.apply { call.respond(this.toMedicalTechnologyApiDto()) }
68+
?: call.respond(HttpStatusCode.NotFound)
7769
}
7870
delete("$apiPath/medical-technologies/{technologyId}") {
7971
call.respond(

0 commit comments

Comments
 (0)