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

PI-2687 new endpoint for pnd alerts #540

Merged
merged 1 commit into from
Dec 16, 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 @@ -23,13 +23,13 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.PaginatedResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.paginateWith

@RestController
@RequestMapping("/v1/persons")
@RequestMapping("/v1")
@Tags(Tag(name = "persons"), Tag(name = "alerts"))
class AlertsController(
@Autowired val getAlertsForPersonService: GetAlertsForPersonService,
@Autowired val auditService: AuditService,
) {
@GetMapping("{encodedHmppsId}/alerts")
@GetMapping("/persons/{encodedHmppsId}/alerts")
@Operation(
summary = "Returns alerts associated with a person, sorted by dateCreated (newest first).",
responses = [
Expand All @@ -53,8 +53,9 @@ class AlertsController(
return response.data.paginateWith(page, perPage)
}

@GetMapping("{encodedHmppsId}/alerts/pnd")
@GetMapping("/persons/{encodedHmppsId}/alerts/pnd")
@Operation(
deprecated = true,
summary = "Returns alerts associated with a person, sorted by dateCreated (newest first).",
responses = [
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found alerts for a person with the provided HMPPS ID."),
Expand All @@ -76,4 +77,28 @@ class AlertsController(
auditService.createEvent("GET_PERSON_ALERTS_PND", mapOf("hmppsId" to hmppsId))
return response.data.paginateWith(page, perPage)
}

@GetMapping("/pnd/persons/{encodedHmppsId}/alerts")
@Operation(
summary = "Returns alerts associated with a person, sorted by dateCreated (newest first).",
responses = [
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found alerts for a person with the provided HMPPS ID."),
ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]),
ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]),
],
)
fun getPndPersonAlerts(
@Parameter(description = "A URL-encoded HMPPS identifier", example = "2008%2F0545166T") @PathVariable encodedHmppsId: String,
@Parameter(description = "The page number (starting from 1)", schema = Schema(minimum = "1")) @RequestParam(required = false, defaultValue = "1", name = "page") page: Int,
@Parameter(description = "The maximum number of results for a page", schema = Schema(minimum = "1")) @RequestParam(required = false, defaultValue = "10", name = "perPage") perPage: Int,
): PaginatedResponse<Alert> {
val hmppsId = encodedHmppsId.decodeUrlCharacters()
val response = getAlertsForPersonService.getAlertsForPnd(hmppsId)

if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
throw EntityNotFoundException("Could not find person with id: $hmppsId")
}
auditService.createEvent("GET_PERSON_ALERTS_PND", mapOf("hmppsId" to hmppsId))
return response.data.paginateWith(page, perPage)
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ authorisation:
- "/v1/persons"
- "/v1/persons/[^/]*$"
- "/v1/persons/.*/addresses"
- "/v1/pnd/persons/.*/alerts"
- "/v1/persons/.*/alerts/pnd"
- "/v1/persons/.*/sentences"
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
Expand All @@ -97,6 +98,7 @@ authorisation:
- "/v1/persons/.*/addresses"
- "/v1/persons/.*/adjudications"
- "/v1/persons/.*/alerts"
- "/v1/pnd/persons/.*/alerts"
- "/v1/persons/.*/alerts/pnd"
- "/v1/persons/.*/case-notes"
- "/v1/persons/.*/images"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ authorisation:
- "/v1/persons/.*/addresses"
- "/v1/persons/.*/offences"
- "/v1/persons/.*/alerts"
- "/v1/pnd/persons/.*/alerts"
- "/v1/persons/.*/alerts/pnd"
- "/v1/persons/.*/sentences"
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-local-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ authorisation:
- "/v1/persons/.*/addresses"
- "/v1/persons/.*/offences"
- "/v1/persons/.*/alerts"
- "/v1/pnd/persons/.*/alerts"
- "/v1/persons/.*/alerts/pnd"
- "/v1/persons/.*/sentences"
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ authorisation:
- "/v1/persons/.*/addresses"
- "/v1/persons/.*/offences"
- "/v1/persons/.*/alerts"
- "/v1/pnd/persons/.*/alerts"
- "/v1/persons/.*/alerts/pnd"
- "/v1/persons/.*/sentences"
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ authorisation:
- "/v1/persons/.*/addresses"
- "/v1/persons/.*/offences"
- "/v1/persons/.*/alerts"
- "/v1/pnd/persons/.*/alerts"
- "/v1/persons/.*/alerts/pnd"
- "/v1/persons/.*/sentences"
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class AlertsControllerTest(
val hmppsId = "9999/11111A"
val encodedHmppsId = URLEncoder.encode(hmppsId, StandardCharsets.UTF_8)
val path = "/v1/persons/$encodedHmppsId/alerts"
val pndPath = "/v1/persons/$encodedHmppsId/alerts/pnd"
val pndPath = "/v1/pnd/persons/$encodedHmppsId/alerts"
val mockMvc = IntegrationAPIMockMvc(springMockMvc)

describe("GET $path") {
Expand Down Expand Up @@ -250,7 +250,7 @@ internal class AlertsControllerTest(
val hmppsIdForPersonWithNoAlerts = "1111/22334A"
val encodedHmppsIdForPersonWithNoAlerts =
URLEncoder.encode(hmppsIdForPersonWithNoAlerts, StandardCharsets.UTF_8)
val alertPath = "/v1/persons/$encodedHmppsIdForPersonWithNoAlerts/alerts/pnd"
val alertPath = "/v1/pnd/persons/$encodedHmppsIdForPersonWithNoAlerts/alerts"

whenever(getAlertsForPersonService.getAlertsForPnd(hmppsIdForPersonWithNoAlerts)).thenReturn(
Response(
Expand Down
Loading