Skip to content

Commit

Permalink
PI-1939 - add disposal data to response
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Mar 26, 2024
1 parent e2d09e8 commit 4e1f22e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import uk.gov.justice.digital.hmpps.api.model.Name
import uk.gov.justice.digital.hmpps.api.model.overview.Order
import uk.gov.justice.digital.hmpps.api.model.sentence.*
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
Expand Down Expand Up @@ -61,7 +62,8 @@ class SentenceIntegrationTest {
"Birmingham Court",
LocalDate.now(),
listOf(AdditionalSentence(3, null, null, "Disqualified from Driving"))
)
),
Order("Default Sentence Type", null, LocalDate.now().minusDays(14))
),
Sentence(
OffenceDetails(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package uk.gov.justice.digital.hmpps.api.model.sentence

import uk.gov.justice.digital.hmpps.api.model.overview.Order

data class Sentence(
val offenceDetails: OffenceDetails,
val conviction: Conviction? = null,
val order: Order? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Event
interface EventSentenceRepository : JpaRepository<Event, Long> {
@Query(
"SELECT e FROM Event e " +
"LEFT JOIN FETCH e.disposal d " +
"LEFT JOIN FETCH d.type t " +
"LEFT JOIN FETCH e.court c " +
"LEFT JOIN FETCH e.mainOffence m " +
"LEFT JOIN FETCH e.additionalOffences ao " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package uk.gov.justice.digital.hmpps.service

import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.api.model.Name
import uk.gov.justice.digital.hmpps.api.model.overview.Order
import uk.gov.justice.digital.hmpps.api.model.sentence.*
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Event
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonRepository
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonSummaryEntity
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.getSummary
import uk.gov.justice.digital.hmpps.api.model.sentence.Offence
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.*
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AdditionalSentenceRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CourtAppearance
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CourtAppearanceRepository
Expand Down Expand Up @@ -47,12 +46,15 @@ class SentenceService(
responsibleCourt = court?.name,
convictionDate = convictionDate,
additionalSentences.map { it.toAdditionalSentence() }
)
),
order = disposal?.toOrder()
)

fun ExtraSentence.toAdditionalSentence(): AdditionalSentence =
AdditionalSentence(length, amount, notes, type.description)

fun PersonSummaryEntity.toName() =
Name(forename, secondName, surname)

fun Disposal.toOrder() = Order(description = type.description, startDate = date, endDate = expectedEndDate())
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.*
import uk.gov.justice.digital.hmpps.api.model.Name
import uk.gov.justice.digital.hmpps.api.model.overview.Order
import uk.gov.justice.digital.hmpps.api.model.sentence.*
import uk.gov.justice.digital.hmpps.data.generator.AdditionalSentenceGenerator
import uk.gov.justice.digital.hmpps.data.generator.CourtAppearanceGenerator
Expand Down Expand Up @@ -124,7 +125,8 @@ class SentenceServiceTest {
AdditionalSentence(3, null, null, "Disqualified from Driving"),
AdditionalSentence(null, 500, "fine notes", "Fine")
)
)
),
Order("Default Sentence Type", null, LocalDate.now().minusDays(14))
)
)
)
Expand Down

0 comments on commit 4e1f22e

Please sign in to comment.