Skip to content

Commit

Permalink
PI-2244 Add referral date to SOC convictions endpoint (#3863)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Jun 4, 2024
1 parent 9817791 commit 0e07163
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
)
Expand Down Expand Up @@ -67,6 +63,7 @@ object ConvictionEventGenerator {
val EVENT_2 = ConvictionEventEntity(
IdGenerator.getAndIncrement(),
LocalDate.now(),
LocalDate.now(),
PERSON_2
)
val MAIN_OFFENCE_2 = MainOffence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,6 +19,8 @@ class ConvictionEventEntity(

val convictionDate: LocalDate?,

val referralDate: LocalDate,

@ManyToOne
@JoinColumn(name = "offender_id", nullable = false)
val convictionEventPerson: ConvictionEventPerson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Offence>,
val sentence: Sentence?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -65,6 +59,7 @@ class ConvictionService(
Conviction(
convictionEventEntity.id,
convictionEventEntity.convictionDate,
convictionEventEntity.referralDate,
convictionEventEntity.disposal?.type?.description ?: "unknown",
offences,
convictionEventEntity.disposal?.asModel(custody)
Expand Down

0 comments on commit 0e07163

Please sign in to comment.