Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes to endpoints to make them less confusing #521

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<HmppsId?> {
val nomisNumber = encodedNomisNumber.decodeUrlCharacters()

val response = getHmppsIdService.execute(nomisNumber)

if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
Expand All @@ -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<NomisNumber?> {
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")
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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/[^/]*$"
3 changes: 2 additions & 1 deletion src/main/resources/application-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application-local-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading