diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/StaffControllerIntegrationTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/StaffControllerIntegrationTest.kt index eaa633a563..57b05057d2 100644 --- a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/StaffControllerIntegrationTest.kt +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/StaffControllerIntegrationTest.kt @@ -26,8 +26,8 @@ class StaffControllerIntegrationTest { mockMvc .perform(get("/approved-premises/${approvedPremises.code.code}/staff").withToken()) .andExpect(status().isOk) - .andExpect(jsonPath("$.numberOfElements", equalTo(3))) - .andExpect(jsonPath("$.size", equalTo(100))) + .andExpect(jsonPath("$.page.totalElements", equalTo(3))) + .andExpect(jsonPath("$.page.size", equalTo(100))) .andExpect( jsonPath( "$.content[*].name.surname", @@ -43,8 +43,9 @@ class StaffControllerIntegrationTest { mockMvc .perform(get("/approved-premises/${approvedPremises.code.code}/staff").withToken()) .andExpect(status().isOk) - .andExpect(jsonPath("$.numberOfElements", equalTo(0))) - .andExpect(jsonPath("$.totalElements", equalTo(0))) + .andExpect(jsonPath("$.content.size()", equalTo(0))) + .andExpect(jsonPath("$.page.totalPages", equalTo(0))) + .andExpect(jsonPath("$.page.totalElements", equalTo(0))) } @Test @@ -60,7 +61,7 @@ class StaffControllerIntegrationTest { val approvedPremises = ApprovedPremisesGenerator.DEFAULT mockMvc.perform(get("/approved-premises/${approvedPremises.code.code}/staff?keyWorker=true").withToken()) .andExpect(status().isOk) - .andExpect(jsonPath("$.numberOfElements", equalTo(1))) + .andExpect(jsonPath("$.page.totalElements", equalTo(1))) .andExpect(jsonPath("$.content[*].name.surname", equalTo(listOf("Key-worker")))) .andExpect(jsonPath("$.content[*].keyWorker", equalTo(listOf(true)))) } diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/StaffService.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/StaffService.kt index 01cb81dd47..6f131a8e9d 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/StaffService.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/StaffService.kt @@ -1,7 +1,7 @@ package uk.gov.justice.digital.hmpps.service -import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable +import org.springframework.data.web.PagedModel import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.exception.NotFoundException @@ -23,7 +23,7 @@ class StaffService( approvedPremisesCode: String, keyWorkersOnly: Boolean, pageable: Pageable - ): Page { + ): PagedModel { if (!approvedPremisesRepository.existsByCodeCode(approvedPremisesCode)) { throw NotFoundException("Approved Premises", "code", approvedPremisesCode) } @@ -36,7 +36,7 @@ class StaffService( staffRepository.findAllStaffLinkedToApprovedPremisesTeam(approvedPremisesCode, pageable).map { it.toResponse(approvedPremisesCode) } - } + }.let { PagedModel(it) } } fun getStaffByUsername(username: String) = diff --git a/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt b/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt index 11bd9d8c79..7846649d0c 100644 --- a/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt +++ b/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt @@ -67,7 +67,7 @@ internal class CorePersonIntegrationTest { mockMvc .perform(get("/all-probation-cases?sort=crn,desc").withToken()) .andExpect(status().is2xxSuccessful) - .andExpect(jsonPath("totalElements", equalTo(2))) + .andExpect(jsonPath("page.totalElements", equalTo(2))) .andExpect(jsonPath("content[0].identifiers.crn", equalTo(minPerson.identifiers.crn))) .andExpect(jsonPath("content[1].identifiers.crn", equalTo(fullPerson.identifiers.crn))) } diff --git a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/PersonResource.kt b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/PersonResource.kt index 552b418ad9..715c41c893 100644 --- a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/PersonResource.kt +++ b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/PersonResource.kt @@ -1,6 +1,7 @@ package uk.gov.justice.digital.hmpps.api.resource import org.springframework.data.domain.Pageable +import org.springframework.data.web.PagedModel import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable @@ -24,5 +25,5 @@ class PersonResource(private val personService: PersonService) { } @GetMapping(value = ["/all-probation-cases"]) - fun getPersonDetails(pageable: Pageable) = personService.getAllPersonDetails(pageable) + fun getPersonDetails(pageable: Pageable) = PagedModel(personService.getAllPersonDetails(pageable)) }