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-2696 Add timestamp to court appearance date #4491

Merged
merged 1 commit into from
Dec 13, 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 @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +32,7 @@ class Court(
class CourtAppearanceEntity(

@Column(name = "appearance_date")
val appearanceDate: LocalDate,
val appearanceDate: ZonedDateTime,

@Id
@Column(name = "court_appearance_id")
Expand Down Expand Up @@ -102,7 +104,7 @@ interface CourtAppearanceRepository : JpaRepository<CourtAppearanceEntity, Long>
order by ca.appearanceDate desc
"""
)
fun findMostRecentCourtAppearancesByCrn(dateFrom: LocalDate, crn: String): List<CourtAppearanceEntity>
fun findMostRecentCourtAppearancesByCrn(dateFrom: ZonedDateTime, crn: String): List<CourtAppearanceEntity>

@Query(
"""
Expand All @@ -112,7 +114,10 @@ interface CourtAppearanceRepository : JpaRepository<CourtAppearanceEntity, Long>
order by ca.appearanceDate desc
"""
)
fun findMostRecentCourtAppearancesByNomsNumber(dateFrom: LocalDate, nomsNumber: String): List<CourtAppearanceEntity>
fun findMostRecentCourtAppearancesByNomsNumber(
dateFrom: ZonedDateTime,
nomsNumber: String
): List<CourtAppearanceEntity>

@Query(
"""
Expand All @@ -124,6 +129,6 @@ interface CourtAppearanceRepository : JpaRepository<CourtAppearanceEntity, Long>
)
fun findCourtAppearancesForCrns(
crns: List<String>,
dateFrom: LocalDate = LocalDate.now()
dateFrom: ZonedDateTime = LocalDate.now().atStartOfDay(EuropeLondon)
): List<CourtAppearanceEntity>
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading