From 0e07163bffaeb67929578725e1b1ceedff484a29 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Tue, 4 Jun 2024 12:04:57 +0100 Subject: [PATCH] PI-2244 Add referral date to SOC convictions endpoint (#3863) --- .../hmpps/data/generator/ConvictionEventGenerator.kt | 11 ++++------- .../digital/hmpps/ConvictionsIntegrationTest.kt | 2 ++ .../digital/hmpps/CourtAppearancesIntegrationTest.kt | 2 +- .../digital/hmpps/entity/ConvictionEventEntity.kt | 11 +++-------- .../uk/gov/justice/digital/hmpps/model/Conviction.kt | 1 + .../digital/hmpps/service/ConvictionService.kt | 11 +++-------- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt b/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt index d05bb983ee..081170b17d 100644 --- a/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt +++ b/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt @@ -1,12 +1,6 @@ package uk.gov.justice.digital.hmpps.data.generator -import uk.gov.justice.digital.hmpps.entity.AdditionalOffence -import uk.gov.justice.digital.hmpps.entity.ConvictionEventEntity -import uk.gov.justice.digital.hmpps.entity.ConvictionEventPerson -import uk.gov.justice.digital.hmpps.entity.Disposal -import uk.gov.justice.digital.hmpps.entity.DisposalType -import uk.gov.justice.digital.hmpps.entity.MainOffence -import uk.gov.justice.digital.hmpps.entity.Offence +import uk.gov.justice.digital.hmpps.entity.* import java.time.LocalDate object ConvictionEventGenerator { @@ -30,11 +24,13 @@ object ConvictionEventGenerator { val DEFAULT_EVENT = ConvictionEventEntity( IdGenerator.getAndIncrement(), LocalDate.now().minusDays(1), + LocalDate.now().minusDays(2), PERSON ) val INACTIVE_EVENT = ConvictionEventEntity( IdGenerator.getAndIncrement(), LocalDate.now(), + LocalDate.now().minusDays(1), PERSON, active = false ) @@ -67,6 +63,7 @@ object ConvictionEventGenerator { val EVENT_2 = ConvictionEventEntity( IdGenerator.getAndIncrement(), LocalDate.now(), + LocalDate.now(), PERSON_2 ) val MAIN_OFFENCE_2 = MainOffence( diff --git a/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionsIntegrationTest.kt b/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionsIntegrationTest.kt index 9206d93db9..e049c612f8 100644 --- a/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionsIntegrationTest.kt +++ b/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionsIntegrationTest.kt @@ -61,6 +61,7 @@ internal class ConvictionsIntegrationTest { Conviction( ConvictionEventGenerator.DEFAULT_EVENT.id, ConvictionEventGenerator.DEFAULT_EVENT.convictionDate, + ConvictionEventGenerator.DEFAULT_EVENT.referralDate, ConvictionEventGenerator.DISPOSAL_TYPE.description, listOf( Offence( @@ -100,6 +101,7 @@ internal class ConvictionsIntegrationTest { val inactiveConviction = Conviction( ConvictionEventGenerator.INACTIVE_EVENT.id, ConvictionEventGenerator.INACTIVE_EVENT.convictionDate, + ConvictionEventGenerator.INACTIVE_EVENT.referralDate, "unknown", listOf(), null diff --git a/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt b/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt index e557f41c69..f2509ca3c2 100644 --- a/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt +++ b/projects/soc-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt @@ -24,7 +24,7 @@ internal class CourtAppearancesIntegrationTest { @Test fun `API call retuns a success response`() { val crn = CourtAppearanceGenerator.DEFAULT_PERSON.crn - val detailResponse = mockMvc + mockMvc .perform(get("/court-appearances/$crn").withToken()) .andExpect(status().is2xxSuccessful) .andExpectJson(getCourtAppearances()) diff --git a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt index 3a37e3c9c9..fe319785bd 100644 --- a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt +++ b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt @@ -1,13 +1,6 @@ package uk.gov.justice.digital.hmpps.entity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Id -import jakarta.persistence.JoinColumn -import jakarta.persistence.ManyToOne -import jakarta.persistence.OneToMany -import jakarta.persistence.OneToOne -import jakarta.persistence.Table +import jakarta.persistence.* import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction import org.springframework.data.jpa.repository.EntityGraph @@ -26,6 +19,8 @@ class ConvictionEventEntity( val convictionDate: LocalDate?, + val referralDate: LocalDate, + @ManyToOne @JoinColumn(name = "offender_id", nullable = false) val convictionEventPerson: ConvictionEventPerson, diff --git a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/Conviction.kt b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/Conviction.kt index 4e0f1f74c4..0bb28d5b00 100644 --- a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/Conviction.kt +++ b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/Conviction.kt @@ -5,6 +5,7 @@ import java.time.LocalDate data class Conviction( val convictionId: Long, val convictionDate: LocalDate?, + val referralDate: LocalDate, val outcome: String, val offences: List, val sentence: Sentence? diff --git a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ConvictionService.kt b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ConvictionService.kt index 6ca57f4165..ef1d4d4006 100644 --- a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ConvictionService.kt +++ b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ConvictionService.kt @@ -2,17 +2,11 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service import uk.gov.justice.digital.hmpps.controller.IdentifierType -import uk.gov.justice.digital.hmpps.entity.ConvictionEventRepository -import uk.gov.justice.digital.hmpps.entity.CustodyRepository -import uk.gov.justice.digital.hmpps.entity.Disposal +import uk.gov.justice.digital.hmpps.entity.* import uk.gov.justice.digital.hmpps.entity.KeyDate -import uk.gov.justice.digital.hmpps.entity.ReferenceData -import uk.gov.justice.digital.hmpps.model.Conviction -import uk.gov.justice.digital.hmpps.model.ConvictionsContainer +import uk.gov.justice.digital.hmpps.model.* import uk.gov.justice.digital.hmpps.model.Custody -import uk.gov.justice.digital.hmpps.model.CustodyStatus import uk.gov.justice.digital.hmpps.model.Offence -import uk.gov.justice.digital.hmpps.model.Sentence @Service class ConvictionService( @@ -65,6 +59,7 @@ class ConvictionService( Conviction( convictionEventEntity.id, convictionEventEntity.convictionDate, + convictionEventEntity.referralDate, convictionEventEntity.disposal?.type?.description ?: "unknown", offences, convictionEventEntity.disposal?.asModel(custody)