|
| 1 | +package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person |
| 2 | + |
| 3 | +import io.swagger.v3.oas.annotations.Operation |
| 4 | +import io.swagger.v3.oas.annotations.Parameter |
| 5 | +import io.swagger.v3.oas.annotations.media.Content |
| 6 | +import io.swagger.v3.oas.annotations.media.Schema |
| 7 | +import io.swagger.v3.oas.annotations.responses.ApiResponse |
| 8 | +import io.swagger.v3.oas.annotations.tags.Tag |
| 9 | +import io.swagger.v3.oas.annotations.tags.Tags |
| 10 | +import org.springframework.beans.factory.annotation.Autowired |
| 11 | +import org.springframework.web.bind.annotation.GetMapping |
| 12 | +import org.springframework.web.bind.annotation.PathVariable |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping |
| 14 | +import org.springframework.web.bind.annotation.RestController |
| 15 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException |
| 16 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters |
| 17 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse |
| 18 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule |
| 19 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError |
| 20 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetInductionScheduleForPersonService |
| 21 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService |
| 22 | + |
| 23 | +@RestController |
| 24 | +@RequestMapping("/v1/persons") |
| 25 | +@Tags(Tag(name = "persons"), Tag(name = "alerts")) |
| 26 | +class PLPController( |
| 27 | + @Autowired val getInductionScheduleForPersonService: GetInductionScheduleForPersonService, |
| 28 | + @Autowired val auditService: AuditService, |
| 29 | +) { |
| 30 | + @GetMapping("{encodedHmppsId}/plp/inductionScheduleUpdated") |
| 31 | + @Operation( |
| 32 | + summary = "Returns plp the induction schedule associated with a person.", |
| 33 | + responses = [ |
| 34 | + ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found induction schedule for a person with the provided HMPPS ID."), |
| 35 | + ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]), |
| 36 | + ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]), |
| 37 | + ], |
| 38 | + ) |
| 39 | + fun getInductionSchedule( |
| 40 | + @Parameter(description = "A URL-encoded HMPPS identifier", example = "2008%2F0545166T") @PathVariable encodedHmppsId: String, |
| 41 | + ): DataResponse<InductionSchedule> { |
| 42 | + val hmppsId = encodedHmppsId.decodeUrlCharacters() |
| 43 | + val response = getInductionScheduleForPersonService.execute(hmppsId) |
| 44 | + |
| 45 | + if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) { |
| 46 | + throw EntityNotFoundException("Could not find person with id: $hmppsId") |
| 47 | + } |
| 48 | + auditService.createEvent("GET_INDUCTION_SCHEDULE", mapOf("hmppsId" to hmppsId)) |
| 49 | + return DataResponse(response.data) |
| 50 | + } |
| 51 | +} |
0 commit comments