From 80ebcf09d5ef910040fcde06833838ee259e1c93 Mon Sep 17 00:00:00 2001 From: Andrea Giulianelli Date: Tue, 28 Feb 2023 18:46:15 +0100 Subject: [PATCH] feat: implement endpoint to create and get a medical technology --- .../infrastructure/api/APIController.kt | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/infrastructure/api/APIController.kt b/src/main/kotlin/infrastructure/api/APIController.kt index a24676bc..8e66d6db 100644 --- a/src/main/kotlin/infrastructure/api/APIController.kt +++ b/src/main/kotlin/infrastructure/api/APIController.kt @@ -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 @@ -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().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!")