Skip to content

Commit 215418d

Browse files
committed
add docs info to controller; add endpoint to private-prisons role
1 parent c2be7b2 commit 215418d

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/CellLocationController.kt

+22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person
22

3+
import io.swagger.v3.oas.annotations.Operation
34
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
48
import io.swagger.v3.oas.annotations.tags.Tag
9+
import jakarta.validation.ValidationException
510
import org.springframework.beans.factory.annotation.Autowired
611
import org.springframework.web.bind.annotation.GetMapping
712
import org.springframework.web.bind.annotation.PathVariable
@@ -23,6 +28,20 @@ class CellLocationController(
2328
@Autowired val auditService: AuditService,
2429
@Autowired val getCellLocationForPersonService: GetCellLocationForPersonService,
2530
) {
31+
@Operation(
32+
summary = "Returns the cell location of a person.",
33+
description = "<b>Applicable filters</b>: <ul><li>prisons</li></ul>",
34+
responses = [
35+
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found a persons cell location."),
36+
ApiResponse(
37+
responseCode = "400",
38+
description = "The HMPPS ID provided has an invalid format.",
39+
content = [Content(schema = Schema(ref = "#/components/schemas/BadRequest"))],
40+
),
41+
ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]),
42+
ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]),
43+
],
44+
)
2645
@GetMapping("{hmppsId}/cell-location")
2746
fun getPersonCellLocation(
2847
@Parameter(description = "The HMPPS ID of the person") @PathVariable hmppsId: String,
@@ -33,6 +52,9 @@ class CellLocationController(
3352
if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
3453
throw EntityNotFoundException("Could not find cell location for id: $hmppsId")
3554
}
55+
if (response.hasError(UpstreamApiError.Type.BAD_REQUEST)) {
56+
throw ValidationException("Invalid HMPPS ID: $hmppsId")
57+
}
3658

3759
auditService.createEvent("GET_PERSON_CELL_LOCATION", mapOf("hmppsId" to hmppsId))
3860

src/main/resources/globals.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ globals:
1212
- "/v1/persons/.*/visit-orders"
1313
- "/v1/persons/.*/visit/future"
1414
- "/v1/persons/.*/alerts"
15+
- "/v1/persons/.*/cell-location"
1516
- "/v1/prison/prisoners"
1617
- "/v1/prison/prisoners/[^/]*$"
1718
- "/v1/prison/.*/prisoners/[^/]*/balances$"

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/CellLocationControllerTest.kt

+19
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ internal class CellLocationControllerTest(
118118
result.response.status.shouldBe(HttpStatus.NOT_FOUND.value())
119119
}
120120

121+
it("returns a 400 BAD Request status code when an invalid hmpps id is found in the upstream API") {
122+
whenever(getCellLocationForPersonService.execute(hmppsId, filters)).thenReturn(
123+
Response(
124+
data = null,
125+
errors =
126+
listOf(
127+
UpstreamApiError(
128+
causedBy = UpstreamApi.NOMIS,
129+
type = UpstreamApiError.Type.BAD_REQUEST,
130+
),
131+
),
132+
),
133+
)
134+
135+
val result = mockMvc.performAuthorised(path)
136+
137+
result.response.status.shouldBe(HttpStatus.BAD_REQUEST.value())
138+
}
139+
121140
it("fails with the appropriate error when an upstream service is down") {
122141
whenever(getCellLocationForPersonService.execute(hmppsId, filters)).doThrow(
123142
WebClientResponseException(500, "MockError", null, null, null, null),

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/integration/person/PersonIntegrationTest.kt

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration.person
22

33
import org.junit.jupiter.api.Test
4-
import org.junit.jupiter.params.ParameterizedTest
5-
import org.junit.jupiter.params.provider.ValueSource
64
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
75
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
86
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration.IntegrationTestBase
@@ -46,10 +44,10 @@ class PersonIntegrationTest : IntegrationTestBase() {
4644
)
4745
}
4846

49-
@ParameterizedTest
50-
@ValueSource(strings = ["2004%2F13116M", "G2996UX"])
51-
fun `returns person cell location if in prison`(hmppsId: String) {
52-
callApi("$basePath/$hmppsId/cell-location")
47+
// Cell Location tests
48+
@Test
49+
fun `returns person cell location if in prison`() {
50+
callApi("$basePath/$nomsId/cell-location")
5351
.andExpect(status().isOk)
5452
.andExpect(
5553
content().json(
@@ -60,6 +58,25 @@ class PersonIntegrationTest : IntegrationTestBase() {
6058
)
6159
}
6260

61+
@Test
62+
fun `cell location return a 404 for person in wrong prison`() {
63+
callApiWithCN("$basePath/$nomsId/cell-location", limitedPrisonsCn)
64+
.andExpect(status().isNotFound)
65+
}
66+
67+
@Test
68+
fun `cell location return a 404 when no prisons in filter`() {
69+
callApiWithCN("$basePath/$nomsId/cell-location", noPrisonsCn)
70+
.andExpect(status().isNotFound)
71+
}
72+
73+
@Test
74+
fun `cell location return a 400 when invalid noms passed in`() {
75+
callApi("$basePath/$invalidNomsId/cell-location")
76+
.andExpect(status().isBadRequest)
77+
}
78+
79+
// Prisoner Contacts
6380
@Test
6481
fun `returns a prisoners contacts`() {
6582
val params = "?page=1&size=10"

0 commit comments

Comments
 (0)