Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* PI-1964

* Formatting changes

* PI-1964

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
anthony-britton-moj and github-actions[bot] authored Feb 29, 2024
1 parent 0d2a319 commit fbbd676
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object ConvictionEventGenerator {
)
val DEFAULT_EVENT = ConvictionEventEntity(
IdGenerator.getAndIncrement(),
LocalDate.now(),
LocalDate.now().minusDays(1),
PERSON
)
val INACTIVE_EVENT = ConvictionEventEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.hibernate.annotations.Immutable
import org.hibernate.annotations.SQLRestriction
import org.springframework.data.jpa.repository.EntityGraph
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import java.time.LocalDate

@Immutable
Expand Down Expand Up @@ -165,14 +166,20 @@ class Offence(
)

interface ConvictionEventRepository : JpaRepository<ConvictionEventEntity, Long> {
@EntityGraph(
attributePaths = [
"mainOffence.offence",
"additionalOffences.offence",
"disposal.type"
]
@Query(
"""
select c from ConvictionEventEntity c
join fetch c.disposal d
join fetch d.type dt
join fetch c.mainOffence mo
join fetch mo.offence
left join fetch c.additionalOffences ao
left join fetch ao.offence
where c.convictionEventPerson.id = :personId and c.active = true
order by c.convictionDate desc
"""
)
fun getAllByConvictionEventPersonIdAndActiveIsTrueOrderByConvictionDateDesc(personId: Long): List<ConvictionEventEntity>
fun getActiveSentencedConvictions(personId: Long): List<ConvictionEventEntity>

@EntityGraph(
attributePaths = [
Expand Down Expand Up @@ -212,4 +219,4 @@ interface ConvictionEventRepository : JpaRepository<ConvictionEventEntity, Long>
}

fun ConvictionEventRepository.getLatestConviction(personId: Long) =
getAllByConvictionEventPersonIdAndActiveIsTrueOrderByConvictionDateDesc(personId).firstOrNull()
getActiveSentencedConvictions(personId).firstOrNull()

0 comments on commit fbbd676

Please sign in to comment.