diff --git a/projects/pathfinder-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtAppearanceGenerator.kt b/projects/pathfinder-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtAppearanceGenerator.kt index 9c6f89e521..0e3de0d43c 100644 --- a/projects/pathfinder-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtAppearanceGenerator.kt +++ b/projects/pathfinder-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtAppearanceGenerator.kt @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.data.generator import uk.gov.justice.digital.hmpps.entity.* import java.time.LocalDate +import java.time.ZoneId object CourtAppearanceGenerator { val DEFAULT_PERSON = CourtAppearancePerson( @@ -28,7 +29,7 @@ object CourtAppearanceGenerator { "Breach - Continued/Fine" ) val DEFAULT_CA = CourtAppearanceEntity( - LocalDate.now(), + LocalDate.now().plusDays(1).atTime(12, 30).atZone(ZoneId.systemDefault()), IdGenerator.getAndIncrement(), DEFAULT_EVENT, DEFAULT_CA_TYPE, @@ -44,14 +45,14 @@ object CourtAppearanceGenerator { PERSON_2 ) val CA_2 = CourtAppearanceEntity( - LocalDate.now(), + LocalDate.now().plusDays(1).atTime(12, 30).atZone(ZoneId.systemDefault()), IdGenerator.getAndIncrement(), EVENT_2, DEFAULT_CA_TYPE, DEFAULT_COURT ) val CA_3 = CourtAppearanceEntity( - LocalDate.of(2090, 1, 1), + LocalDate.of(2090, 1, 1).atStartOfDay(ZoneId.systemDefault()), IdGenerator.getAndIncrement(), EVENT_2, DEFAULT_CA_TYPE, diff --git a/projects/pathfinder-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt b/projects/pathfinder-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt index a66a711cd1..897804e43e 100644 --- a/projects/pathfinder-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt +++ b/projects/pathfinder-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt @@ -15,9 +15,9 @@ import uk.gov.justice.digital.hmpps.model.CourtAppearance import uk.gov.justice.digital.hmpps.model.CourtAppearancesContainer import uk.gov.justice.digital.hmpps.model.Type import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.andExpectJson +import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.objectMapper import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken -import java.time.LocalDate @AutoConfigureMockMvc @SpringBootTest(webEnvironment = RANDOM_PORT) @@ -56,7 +56,7 @@ internal class CourtAppearancesIntegrationTest { "courtAppearances": { "X012771": [ { - "appearanceDate": "${LocalDate.now()}", + "appearanceDate": ${objectMapper.writeValueAsString(CourtAppearanceGenerator.DEFAULT_CA.appearanceDate)}, "type": { "code": "T", "description": "Trial/Adjournment" @@ -70,7 +70,7 @@ internal class CourtAppearancesIntegrationTest { ], "X012774": [ { - "appearanceDate": "2090-01-01", + "appearanceDate": ${objectMapper.writeValueAsString(CourtAppearanceGenerator.CA_3.appearanceDate)}, "type": { "code": "T", "description": "Trial/Adjournment" @@ -82,7 +82,7 @@ internal class CourtAppearancesIntegrationTest { "offenderId": ${CourtAppearanceGenerator.PERSON_2.id} }, { - "appearanceDate": "${LocalDate.now()}", + "appearanceDate": ${objectMapper.writeValueAsString(CourtAppearanceGenerator.CA_2.appearanceDate)}, "type": { "code": "T", "description": "Trial/Adjournment" diff --git a/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/CourtAppearanceEntity.kt b/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/CourtAppearanceEntity.kt index 039db2482f..51516a235f 100644 --- a/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/CourtAppearanceEntity.kt +++ b/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/CourtAppearanceEntity.kt @@ -5,7 +5,9 @@ import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query +import uk.gov.justice.digital.hmpps.datetime.EuropeLondon import java.time.LocalDate +import java.time.ZonedDateTime @Entity @Immutable @@ -30,7 +32,7 @@ class Court( class CourtAppearanceEntity( @Column(name = "appearance_date") - val appearanceDate: LocalDate, + val appearanceDate: ZonedDateTime, @Id @Column(name = "court_appearance_id") @@ -102,7 +104,7 @@ interface CourtAppearanceRepository : JpaRepository order by ca.appearanceDate desc """ ) - fun findMostRecentCourtAppearancesByCrn(dateFrom: LocalDate, crn: String): List + fun findMostRecentCourtAppearancesByCrn(dateFrom: ZonedDateTime, crn: String): List @Query( """ @@ -112,7 +114,10 @@ interface CourtAppearanceRepository : JpaRepository order by ca.appearanceDate desc """ ) - fun findMostRecentCourtAppearancesByNomsNumber(dateFrom: LocalDate, nomsNumber: String): List + fun findMostRecentCourtAppearancesByNomsNumber( + dateFrom: ZonedDateTime, + nomsNumber: String + ): List @Query( """ @@ -124,6 +129,6 @@ interface CourtAppearanceRepository : JpaRepository ) fun findCourtAppearancesForCrns( crns: List, - dateFrom: LocalDate = LocalDate.now() + dateFrom: ZonedDateTime = LocalDate.now().atStartOfDay(EuropeLondon) ): List } diff --git a/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CourtAppearance.kt b/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CourtAppearance.kt index 3e3a5b5a0d..4a381fdc66 100644 --- a/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CourtAppearance.kt +++ b/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CourtAppearance.kt @@ -1,9 +1,9 @@ package uk.gov.justice.digital.hmpps.model -import java.time.LocalDate +import java.time.ZonedDateTime data class CourtAppearance( - val appearanceDate: LocalDate, + val appearanceDate: ZonedDateTime, val type: Type, val courtCode: String, val courtName: String, diff --git a/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CourtAppearanceService.kt b/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CourtAppearanceService.kt index 4cbfc609b6..1e0e6c9a16 100644 --- a/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CourtAppearanceService.kt +++ b/projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CourtAppearanceService.kt @@ -3,6 +3,7 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.controller.IdentifierType +import uk.gov.justice.digital.hmpps.datetime.EuropeLondon import uk.gov.justice.digital.hmpps.entity.CourtAppearanceEntity import uk.gov.justice.digital.hmpps.entity.CourtAppearanceRepository import uk.gov.justice.digital.hmpps.model.AllCourtAppearancesContainer @@ -18,8 +19,11 @@ class CourtAppearanceService(private val courtAppearanceRepository: CourtAppeara var fromDate = LocalDate.now() requestDate?.also { fromDate = it } val courtAppearances = when (type) { - IdentifierType.CRN -> courtAppearanceRepository.findMostRecentCourtAppearancesByCrn(fromDate, value) - IdentifierType.NOMS -> courtAppearanceRepository.findMostRecentCourtAppearancesByNomsNumber(fromDate, value) + IdentifierType.CRN -> courtAppearanceRepository + .findMostRecentCourtAppearancesByCrn(fromDate.atStartOfDay(EuropeLondon), value) + + IdentifierType.NOMS -> courtAppearanceRepository + .findMostRecentCourtAppearancesByNomsNumber(fromDate.atStartOfDay(EuropeLondon), value) } courtAppearances.forEach { courtAppearanceModels.add(it.toModel()) } return CourtAppearancesContainer(courtAppearanceModels)