Skip to content

Commit

Permalink
PI-2521: Fixed court appearance, convictions (#4226)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 authored Sep 13, 2024
1 parent ce8281e commit c4d1c06
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ internal class RegistrationsIntegrationTest {
.andExpect(status().isOk)
.andReturn().response.contentAsJson<Registrations>()

assertThat(response.registrations.size, equalTo(3))
assertThat(response.registrations[0].active, equalTo(true))
assertThat(response.registrations[1].active, equalTo(false))
assertThat(response.registrations[2].endDate, equalTo(DEREG_2.deRegistrationDate))
assertThat(response.registrations?.size, equalTo(3))
assertThat(response.registrations?.get(0)?.active, equalTo(true))
assertThat(response.registrations?.get(1)?.active, equalTo(false))
assertThat(response.registrations?.get(2)?.endDate, equalTo(DEREG_2.deRegistrationDate))
}

@Test
Expand All @@ -46,7 +46,7 @@ internal class RegistrationsIntegrationTest {
.andExpect(status().isOk)
.andReturn().response.contentAsJson<Registrations>()

assertThat(response.registrations.size, equalTo(2))
assertThat(response.registrations[0].active, equalTo(true))
assertThat(response.registrations?.size, equalTo(2))
assertThat(response.registrations?.get(0)?.active, equalTo(true))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.api.model
import java.time.LocalDate

data class Registrations(
val registrations: List<Registration> = emptyList()
val registrations: List<Registration>? = null
)

data class Registration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class CourtReport(

@Entity
@Table(name = "report_manager")
@SQLRestriction("active_flag = 1 and soft_deleted = 0")
@SQLRestriction("soft_deleted = 0")
class ReportManager(

@JoinColumn(name = "court_report_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ interface EventRepository : JpaRepository<Event, Long> {
case when d.disposal_id is null and ca.outcome_code = '101' then 1 else 0 end as awaitingPsr
from event e
left join disposal d on d.event_id = e.event_id and d.soft_deleted = 0
left join (select ca.event_id, oc.code_value as outcome_code
left join (select distinct ca.event_id, oc.code_value as outcome_code
from court_appearance ca
join r_standard_reference_list oc on ca.outcome_id = oc.standard_reference_list_id) ca
on ca.event_id = e.event_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ class RegistrationService(
if (activeOnly) registrationRepository.findActiveByPersonId(person.id)
else registrationRepository.findByPersonId(person.id)

return Registrations(registrations
val regList = registrations
.filter { r -> !r.softDeleted }
.sortedBy(Registration::date).reversed()
.map(Registration::toRegistration))
.map(Registration::toRegistration)

return Registrations(registrations = regList.takeIf { it.isNotEmpty() })
}
}

Expand Down

0 comments on commit c4d1c06

Please sign in to comment.