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-2291 Switch to Spring's PagedModel for responses #3937

Merged
merged 1 commit into from
Jun 21, 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 @@ -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",
Expand All @@ -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
Expand All @@ -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))))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +23,7 @@ class StaffService(
approvedPremisesCode: String,
keyWorkersOnly: Boolean,
pageable: Pageable
): Page<StaffResponse> {
): PagedModel<StaffResponse> {
if (!approvedPremisesRepository.existsByCodeCode(approvedPremisesCode)) {
throw NotFoundException("Approved Premises", "code", approvedPremisesCode)
}
Expand All @@ -36,7 +36,7 @@ class StaffService(
staffRepository.findAllStaffLinkedToApprovedPremisesTeam(approvedPremisesCode, pageable).map {
it.toResponse(approvedPremisesCode)
}
}
}.let { PagedModel(it) }
}

fun getStaffByUsername(username: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
}