Skip to content

Commit

Permalink
feat: implement endpoint to create and get a medical technology
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGiulianelli committed Mar 7, 2023
1 parent e90930c commit 80ebcf0
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/main/kotlin/infrastructure/api/APIController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

package infrastructure.api

import application.controller.MedicalTechnologyController
import application.controller.RoomController
import application.presenter.api.deserializer.ApiDeserializer.toMedicalTechnology
import application.presenter.api.deserializer.ApiDeserializer.toRoom
import application.presenter.api.model.MedicalTechnologyApiDto
import application.presenter.api.model.RoomApiDto
import application.presenter.api.serializer.ApiSerializer.toMedicalTechnologyApiDto
import application.presenter.api.serializer.ApiSerializer.toRoomApiDto
import application.service.MedicalTechnologyService
import application.service.RoomService
import entity.medicaltechnology.MedicalTechnologyID
import entity.zone.RoomID
import infrastructure.api.util.ApiResponses
import infrastructure.provider.ManagerProvider
Expand Down Expand Up @@ -139,10 +145,39 @@ class APIController(private val provider: ManagerProvider) {
with(app) {
routing {
post("$apiPath/medical-technologies") {
call.respondText("[${Thread.currentThread().name}] Medical Technology POST!")
val medicalTechnology = call.receive<MedicalTechnologyApiDto>().toMedicalTechnology()
MedicalTechnologyService.CreateMedicalTechnology(
medicalTechnology,
MedicalTechnologyController(
provider.medicalTechnologyDigitalTwinManager,
provider.medicalTechnologyDatabaseManager
)
).execute().apply {
when (this) {
null -> call.respond(HttpStatusCode.Conflict)
else -> {
call.response.header(
HttpHeaders.Location,
"http://localhost:$port$apiPath/medical-technologies/${medicalTechnology.id.value}"
)
call.respond(HttpStatusCode.Created)
}
}
}
}
get("$apiPath/medical-technologies/{technologyId}") {
call.respondText("[${Thread.currentThread().name}] Medical Technology GET!")
call.respond(
MedicalTechnologyService.GetMedicalTechnology(
MedicalTechnologyID(call.parameters["technologyId"].orEmpty()),
MedicalTechnologyController(
provider.medicalTechnologyDigitalTwinManager,
provider.medicalTechnologyDatabaseManager
),
call.request.queryParameters["dateTime"]?.let { rawDateTime -> Instant.parse(rawDateTime) }
).execute().let { medicalTechnology ->
medicalTechnology?.toMedicalTechnologyApiDto() ?: HttpStatusCode.NotFound
}
)
}
delete("$apiPath/medical-technologies/{technologyId}") {
call.respondText("[${Thread.currentThread().name}] Medical Technology DELETE!")
Expand Down

0 comments on commit 80ebcf0

Please sign in to comment.