|
| 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 org.springframework.beans.factory.annotation.Autowired |
| 10 | +import org.springframework.web.bind.annotation.GetMapping |
| 11 | +import org.springframework.web.bind.annotation.PathVariable |
| 12 | +import org.springframework.web.bind.annotation.RequestMapping |
| 13 | +import org.springframework.web.bind.annotation.RestController |
| 14 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException |
| 15 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters |
| 16 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.* |
| 17 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisPersonAccount |
| 18 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetPersonPrisonAccountService |
| 19 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService |
| 20 | + |
| 21 | +@RestController |
| 22 | +@RequestMapping("/v0/prison") |
| 23 | +@Tag(name = "prison") |
| 24 | +class PrisonController(@Autowired val auditService: AuditService, |
| 25 | + @Autowired val getPersonPrisonAccount: GetPersonPrisonAccountService |
| 26 | +) { |
| 27 | + @GetMapping("{encodedHmppsId}") |
| 28 | + @Operation( |
| 29 | + summary = "Returns a person", |
| 30 | + responses = [ |
| 31 | + ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found a person with the provided HMPPS ID."), |
| 32 | + ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]), |
| 33 | + ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]), |
| 34 | + ], |
| 35 | + ) |
| 36 | + fun getPersonsPrison( |
| 37 | + @Parameter(description = "A URL-encoded HMPPS identifier", example = "2008%2F0545166T") @PathVariable encodedHmppsId: String, |
| 38 | + ) : DataResponse<NomisPersonAccount?> { |
| 39 | + val hmppsId = encodedHmppsId.decodeUrlCharacters() |
| 40 | + |
| 41 | + val response = getPersonPrisonAccount.execute(hmppsId) |
| 42 | + |
| 43 | + if (response.data.cash == null) { |
| 44 | + throw EntityNotFoundException("Could not find nomis number with supplied hmppsId: $hmppsId") |
| 45 | + } |
| 46 | + |
| 47 | + auditService.createEvent("EXAMPLE_EVENT_BLA_BLA", mapOf("hmppsId" to hmppsId)) |
| 48 | + return DataResponse(response.data) |
| 49 | + } |
| 50 | +} |
0 commit comments