Skip to content

Commit e81153a

Browse files
PI-2687 new endpoint for pnd alerts
1 parent 78151ac commit e81153a

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

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

+28-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.PaginatedResponse
2323
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.paginateWith
2424

2525
@RestController
26-
@RequestMapping("/v1/persons")
26+
@RequestMapping("/v1")
2727
@Tags(Tag(name = "persons"), Tag(name = "alerts"))
2828
class AlertsController(
2929
@Autowired val getAlertsForPersonService: GetAlertsForPersonService,
3030
@Autowired val auditService: AuditService,
3131
) {
32-
@GetMapping("{encodedHmppsId}/alerts")
32+
@GetMapping("/persons/{encodedHmppsId}/alerts")
3333
@Operation(
3434
summary = "Returns alerts associated with a person, sorted by dateCreated (newest first).",
3535
responses = [
@@ -53,8 +53,9 @@ class AlertsController(
5353
return response.data.paginateWith(page, perPage)
5454
}
5555

56-
@GetMapping("{encodedHmppsId}/alerts/pnd")
56+
@GetMapping("/persons/{encodedHmppsId}/alerts/pnd")
5757
@Operation(
58+
deprecated = true,
5859
summary = "Returns alerts associated with a person, sorted by dateCreated (newest first).",
5960
responses = [
6061
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found alerts for a person with the provided HMPPS ID."),
@@ -76,4 +77,28 @@ class AlertsController(
7677
auditService.createEvent("GET_PERSON_ALERTS_PND", mapOf("hmppsId" to hmppsId))
7778
return response.data.paginateWith(page, perPage)
7879
}
80+
81+
@GetMapping("/pnd/persons/{encodedHmppsId}/alerts")
82+
@Operation(
83+
summary = "Returns alerts associated with a person, sorted by dateCreated (newest first).",
84+
responses = [
85+
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found alerts for a person with the provided HMPPS ID."),
86+
ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]),
87+
ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]),
88+
],
89+
)
90+
fun getPndPersonAlerts(
91+
@Parameter(description = "A URL-encoded HMPPS identifier", example = "2008%2F0545166T") @PathVariable encodedHmppsId: String,
92+
@Parameter(description = "The page number (starting from 1)", schema = Schema(minimum = "1")) @RequestParam(required = false, defaultValue = "1", name = "page") page: Int,
93+
@Parameter(description = "The maximum number of results for a page", schema = Schema(minimum = "1")) @RequestParam(required = false, defaultValue = "10", name = "perPage") perPage: Int,
94+
): PaginatedResponse<Alert> {
95+
val hmppsId = encodedHmppsId.decodeUrlCharacters()
96+
val response = getAlertsForPersonService.getAlertsForPnd(hmppsId)
97+
98+
if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
99+
throw EntityNotFoundException("Could not find person with id: $hmppsId")
100+
}
101+
auditService.createEvent("GET_PERSON_ALERTS_PND", mapOf("hmppsId" to hmppsId))
102+
return response.data.paginateWith(page, perPage)
103+
}
79104
}

src/main/resources/application-dev.yml

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ authorisation:
7676
- "/v1/persons"
7777
- "/v1/persons/[^/]*$"
7878
- "/v1/persons/.*/addresses"
79+
- "/v1/pnd/persons/.*/alerts"
7980
- "/v1/persons/.*/alerts/pnd"
8081
- "/v1/persons/.*/sentences"
8182
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
@@ -97,6 +98,7 @@ authorisation:
9798
- "/v1/persons/.*/addresses"
9899
- "/v1/persons/.*/adjudications"
99100
- "/v1/persons/.*/alerts"
101+
- "/v1/pnd/persons/.*/alerts"
100102
- "/v1/persons/.*/alerts/pnd"
101103
- "/v1/persons/.*/case-notes"
102104
- "/v1/persons/.*/images"

src/main/resources/application-integration-test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ authorisation:
5151
- "/v1/persons/.*/addresses"
5252
- "/v1/persons/.*/offences"
5353
- "/v1/persons/.*/alerts"
54+
- "/v1/pnd/persons/.*/alerts"
5455
- "/v1/persons/.*/alerts/pnd"
5556
- "/v1/persons/.*/sentences"
5657
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"

src/main/resources/application-local-docker.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ authorisation:
2525
- "/v1/persons/.*/addresses"
2626
- "/v1/persons/.*/offences"
2727
- "/v1/persons/.*/alerts"
28+
- "/v1/pnd/persons/.*/alerts"
2829
- "/v1/persons/.*/alerts/pnd"
2930
- "/v1/persons/.*/sentences"
3031
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"

src/main/resources/application-local.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ authorisation:
3232
- "/v1/persons/.*/addresses"
3333
- "/v1/persons/.*/offences"
3434
- "/v1/persons/.*/alerts"
35+
- "/v1/pnd/persons/.*/alerts"
3536
- "/v1/persons/.*/alerts/pnd"
3637
- "/v1/persons/.*/sentences"
3738
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"

src/main/resources/application-test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ authorisation:
5151
- "/v1/persons/.*/addresses"
5252
- "/v1/persons/.*/offences"
5353
- "/v1/persons/.*/alerts"
54+
- "/v1/pnd/persons/.*/alerts"
5455
- "/v1/persons/.*/alerts/pnd"
5556
- "/v1/persons/.*/sentences"
5657
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal class AlertsControllerTest(
3939
val hmppsId = "9999/11111A"
4040
val encodedHmppsId = URLEncoder.encode(hmppsId, StandardCharsets.UTF_8)
4141
val path = "/v1/persons/$encodedHmppsId/alerts"
42-
val pndPath = "/v1/persons/$encodedHmppsId/alerts/pnd"
42+
val pndPath = "/v1/pnd/persons/$encodedHmppsId/alerts"
4343
val mockMvc = IntegrationAPIMockMvc(springMockMvc)
4444

4545
describe("GET $path") {
@@ -250,7 +250,7 @@ internal class AlertsControllerTest(
250250
val hmppsIdForPersonWithNoAlerts = "1111/22334A"
251251
val encodedHmppsIdForPersonWithNoAlerts =
252252
URLEncoder.encode(hmppsIdForPersonWithNoAlerts, StandardCharsets.UTF_8)
253-
val alertPath = "/v1/persons/$encodedHmppsIdForPersonWithNoAlerts/alerts/pnd"
253+
val alertPath = "/v1/pnd/persons/$encodedHmppsIdForPersonWithNoAlerts/alerts"
254254

255255
whenever(getAlertsForPersonService.getAlertsForPnd(hmppsIdForPersonWithNoAlerts)).thenReturn(
256256
Response(

0 commit comments

Comments
 (0)