Skip to content

Commit

Permalink
feat: implement get surgery report api
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGiulianelli committed May 20, 2023
1 parent 44d2d47 commit 43ca53d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/kotlin/infrastructure/api/SurgeryReportAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
package infrastructure.api

import application.presenter.api.model.apiresponse.ApiResponses
import application.presenter.api.serialization.SurgeryReportSerializer.toApiDto
import application.service.SurgeryReportService
import entity.process.SurgicalProcessID
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
Expand All @@ -28,6 +30,7 @@ import usecase.repository.SurgeryReportRepository
fun Application.surgeryReportAPI(apiPath: String, port: Int, surgeryReportRepository: SurgeryReportRepository) {
routing {
getAllSurgeryReportEntriesRoute(apiPath, port, surgeryReportRepository)
getSurgeryReportRoute(apiPath, surgeryReportRepository)
}
}

Expand All @@ -42,3 +45,16 @@ private fun Route.getAllSurgeryReportEntriesRoute(
call.response.status(if (entries.isNotEmpty()) HttpStatusCode.OK else HttpStatusCode.NoContent)
call.respond(ApiResponses.ResponseEntryList(entries, entries.size))
}

private fun Route.getSurgeryReportRoute(apiPath: String, surgeryReportRepository: SurgeryReportRepository) =
get("$apiPath/reports/{surgicalProcessId}") {
SurgeryReportService.GetSurgeryReport(
SurgicalProcessID(call.parameters["surgicalProcessId"].orEmpty()),
surgeryReportRepository,
).execute().apply {
when (this) {
null -> call.respond(HttpStatusCode.NotFound)
else -> call.respond(this.toApiDto())
}
}
}

0 comments on commit 43ca53d

Please sign in to comment.