diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/HmppsIdController.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/HmppsIdController.kt index 7cd9c92c4..4d35d62ad 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/HmppsIdController.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/HmppsIdController.kt @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.HmppsId import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.NomisNumber @@ -25,12 +24,20 @@ class HmppsIdController( @Autowired val getHmppsIdService: GetHmppsIdService, @Autowired val auditService: AuditService, ) { - @GetMapping("nomis-number/{encodedNomisNumber}") + @GetMapping("nomis-number/{nomisNumber}", "by-nomis-number/{nomisNumber}") + @Operation( + summary = "Return a HMPPS id for a given nomis number", + description = """Accepts a nomis number and looks up the corresponding HMPPS Id (hmppsId). + """, + responses = [ + ApiResponse(responseCode = "200", useReturnTypeSchema = true), + ApiResponse(responseCode = "404", description = "Nomis number could not be found."), + ApiResponse(responseCode = "400", description = "Invalid hmppsId."), + ], + ) fun getHmppsIdByNomisNumber( - @PathVariable encodedNomisNumber: String, + @PathVariable nomisNumber: String, ): DataResponse { - val nomisNumber = encodedNomisNumber.decodeUrlCharacters() - val response = getHmppsIdService.execute(nomisNumber) if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) { @@ -42,24 +49,21 @@ class HmppsIdController( return DataResponse(response.data) } - @GetMapping("{encodedHmppsId}/nomis-number") + @GetMapping("nomis-number/by-hmpps-id/{hmppsId}") @Operation( - summary = "Return NOMS number for a given hmpps Id", - description = """Accepts a HMPPS Id (hmppsId) and looks up the corresponding NOMS number. + summary = "Return nomis number for a given HMPPS Id", + description = """Accepts a HMPPS Id (hmppsId) and looks up the corresponding nomis number. """, responses = [ ApiResponse(responseCode = "200", useReturnTypeSchema = true), - ApiResponse(responseCode = "404", description = "NOMS number could not be found."), + ApiResponse(responseCode = "404", description = "Nomis number could not be found."), ApiResponse(responseCode = "400", description = "Invalid hmppsId."), ], ) fun getNomisNumberByHMPPSID( - @PathVariable encodedHmppsId: String, + @PathVariable hmppsId: String, ): DataResponse { - val hmppsId = encodedHmppsId.decodeUrlCharacters() - val response = getHmppsIdService.getNomisNumber(hmppsId) - if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) { throw EntityNotFoundException("Could not find nomis number for HMPPS ID: $hmppsId") } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index bcc9960f8..ad0529211 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -57,6 +57,8 @@ authorisation: moj-pes: - "/v1/persons/.*/name" - "/v1/hmpps/id/nomis-number/[^/]*$" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/v1/persons/.*/cell-location" kubernetes-health-check-client: - "/health/liveness" @@ -110,4 +112,5 @@ authorisation: - "/v1/persons/[^/]*$" meganexus: - "/v1/persons/.*/plp/inductionScheduleUpdated" - - "/v1/hmpps/id/.*/nomis-number" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" diff --git a/src/main/resources/application-integration-test.yml b/src/main/resources/application-integration-test.yml index 767aa142f..997619891 100644 --- a/src/main/resources/application-integration-test.yml +++ b/src/main/resources/application-integration-test.yml @@ -71,7 +71,8 @@ authorisation: - "/v1/persons/.*/plp/inductionScheduleUpdated" - "/v1/epf/person-details/.*/[^/]*$" - "/v1/hmpps/id/nomis-number/[^/]*$" - - "/v1/hmpps/id/.*/nomis-number" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/health" - "/health/ping" - "/health/readiness" diff --git a/src/main/resources/application-local-docker.yml b/src/main/resources/application-local-docker.yml index 41f4675f2..53b4d073a 100644 --- a/src/main/resources/application-local-docker.yml +++ b/src/main/resources/application-local-docker.yml @@ -45,7 +45,8 @@ authorisation: - "/v1/persons/.*/plp/inductionScheduleUpdated" - "/v1/epf/person-details/.*/[^/]*$" - "/v1/hmpps/id/nomis-number/[^/]*$" - - "/v1/hmpps/id/.*/nomis-number" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/health" - "/health/ping" - "/health/readiness" diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index e88794782..15a4e5c60 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -52,6 +52,8 @@ authorisation: - "/v1/persons/.*/plp/inductionScheduleUpdated" - "/v1/epf/person-details/.*/[^/]*$" - "/v1/hmpps/id/nomis-number/[^/]*$" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/health" - "/health/ping" - "/health/readiness" diff --git a/src/main/resources/application-preprod.yml b/src/main/resources/application-preprod.yml index 3a2347777..ffb770335 100644 --- a/src/main/resources/application-preprod.yml +++ b/src/main/resources/application-preprod.yml @@ -33,6 +33,8 @@ authorisation: moj-pes: - "/v1/persons/.*/name" - "/v1/hmpps/id/nomis-number/[^/]*$" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/v1/persons/.*/cell-location" kubernetes-health-check-client: - "/health/liveness" diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 33d89859b..8f3fbe610 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -33,6 +33,8 @@ authorisation: moj-pes: - "/v1/persons/.*/name" - "/v1/hmpps/id/nomis-number/[^/]*$" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/v1/persons/.*/cell-location" kubernetes-health-check-client: - "/health/liveness" diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index d4061a0d9..95d72e078 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -72,6 +72,8 @@ authorisation: - "/v1/persons/.*/plp/inductionScheduleUpdated" - "/v1/hmpps/id/nomis-number/[^/]*$" - "/v1/hmpps/id/.*/nomis-number" + - "/v1/hmpps/id/by-nomis-number/[^/]*$" + - "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$" - "/health" - "/health/ping" - "/health/readiness" diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/integration/HmppsIdIntegrationTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/integration/HmppsIdIntegrationTest.kt index a0244d749..c69a2763e 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/integration/HmppsIdIntegrationTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/integration/HmppsIdIntegrationTest.kt @@ -18,9 +18,22 @@ class HmppsIdIntegrationTest : IntegrationTestBase() { ) } + @Test + fun `gets the person detail using new url`() { + callApi("/v1/hmpps/id/by-nomis-number/$nomsId") + .andExpect(status().isOk) + .andExpect( + content().json( + """ + {"data":{"hmppsId":"A123456"}} + """, + ), + ) + } + @Test fun `gets the nomis Id for a HMPPSID where the id is a crn`() { - callApi("/v1/hmpps/id/$crn/nomis-number") + callApi("/v1/hmpps/id/nomis-number/by-hmpps-id/$crn") .andExpect(status().isOk) .andExpect( content().json( @@ -33,7 +46,7 @@ class HmppsIdIntegrationTest : IntegrationTestBase() { @Test fun `gets the nomis Id for a HMPPSID where the id is a NOMIS id`() { - callApi("/v1/hmpps/id/$nomsId/nomis-number") + callApi("/v1/hmpps/id/nomis-number/by-hmpps-id/$nomsId") .andExpect(status().isOk) .andExpect( content().json( @@ -46,7 +59,7 @@ class HmppsIdIntegrationTest : IntegrationTestBase() { @Test fun `gets the nomis Id for a HMPPSID where the id is a NOMIS id AND is not in delius`() { - callApi("/v1/hmpps/id/$nomsIdNotInDelius/nomis-number") + callApi("/v1/hmpps/id/nomis-number/by-hmpps-id/$nomsIdNotInDelius") .andExpect(status().isOk) .andExpect( content().json( @@ -59,7 +72,7 @@ class HmppsIdIntegrationTest : IntegrationTestBase() { @Test fun `gets the nomis Id for a HMPPSID where the id is invalid`() { - callApi("/v1/hmpps/id/invalidId/nomis-number") + callApi("/v1/hmpps/id/nomis-number/by-hmpps-id/invalidId") .andExpect(status().is4xxClientError) .andExpect( content().json( @@ -72,7 +85,7 @@ class HmppsIdIntegrationTest : IntegrationTestBase() { @Test fun `gets the nomis Id for a HMPPSID where the id not found`() { - callApi("/v1/hmpps/id/invalidId/nomis-number") + callApi("/v1/hmpps/id/nomis-number/by-hmpps-id/invalidId") .andExpect(status().is4xxClientError) .andExpect( content().json(