Skip to content

Commit

Permalink
APS-1482 - Refactor GET case-detail endpoint to include offence categ…
Browse files Browse the repository at this point in the history
…ories (#4455)
  • Loading branch information
gregkhawkins authored Nov 21, 2024
1 parent 8b87ca6 commit 0a3fbd7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Of
import java.time.LocalDate

object OffenceGenerator {
val OFFENCE_ONE = generate("OFF1", "Offence One")
val OFFENCE_TWO = generate("OFF2", "Offence Two")
val OFFENCE_ONE = generate("OFF1", "Murder - OFF1", "Murder", "Murder of spouse")
val OFFENCE_TWO = generate(
"OFF2",
"Burglary in a dwelling - OFF2",
"Burglary in a dwelling",
"Burglary (dwelling) with intent to commit, or the commission of, an offence triable only on indictment"
)

fun generate(code: String, description: String, id: Long = IdGenerator.getAndIncrement()) =
Offence(code, description, id)
fun generate(
code: String,
description: String,
mainCategoryDescription: String,
subCategoryDescription: String,
id: Long = IdGenerator.getAndIncrement()
) =
Offence(code, description, mainCategoryDescription, subCategoryDescription, id)

fun generateMainOffence(
event: Event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ class ProbationCaseIntegrationTest {
assertThat(detail.registrations.map { it.description }, equalTo(listOf("Description of ARSO")))
val mainOffence = detail.offences.first { it.main }
assertThat(mainOffence.id, equalTo("M200001"))
assertThat(mainOffence.description, equalTo("Offence One"))
assertThat(mainOffence.description, equalTo("Murder - OFF1"))
assertThat(mainOffence.mainCategoryDescription, equalTo("Murder"))
assertThat(mainOffence.subCategoryDescription, equalTo("Murder of spouse"))
assertThat(mainOffence.date, equalTo(LocalDate.parse("2024-10-11")))
assertThat(mainOffence.eventId, equalTo(100001L))
val otherOffence = detail.offences.first { !it.main }
assertThat(otherOffence.id, equalTo("A300001"))
assertThat(otherOffence.description, equalTo("Offence Two"))
assertThat(otherOffence.description, equalTo("Burglary in a dwelling - OFF2"))
assertThat(otherOffence.mainCategoryDescription, equalTo("Burglary in a dwelling"))
assertThat(
otherOffence.subCategoryDescription,
equalTo("Burglary (dwelling) with intent to commit, or the commission of, an offence triable only on indictment")
)
assertThat(otherOffence.date, equalTo(LocalDate.parse("2024-10-21")))
assertThat(otherOffence.eventId, equalTo(100001L))
assertThat(detail.careLeaver, equalTo(false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface CaseOffence {
val id: Long
val code: String
val description: String
val mainCategoryDescription: String
val subCategoryDescription: String
val date: LocalDate?
val main: Boolean
val eventNumber: String
Expand Down Expand Up @@ -79,6 +81,12 @@ class Offence(
@Column
val description: String,

@Column(name = "main_category_description")
private var mainCategoryDescription: String,

@Column(name = "sub_category_description")
private val subCategoryDescription: String,

@Id
@Column(name = "offence_id")
val id: Long
Expand All @@ -91,6 +99,8 @@ interface MainOffenceRepository : JpaRepository<MainOffence, Long> {
mo.id as id,
mo.offence.code as code,
mo.offence.description as description,
mo.offence.mainCategoryDescription as mainCategoryDescription,
mo.offence.subCategoryDescription as subCategoryDescription,
mo.date as date,
true as main,
mo.event.number as eventNumber,
Expand All @@ -102,6 +112,8 @@ interface MainOffenceRepository : JpaRepository<MainOffence, Long> {
ao.id,
ao.offence.code,
ao.offence.description,
ao.offence.mainCategoryDescription as mainCategoryDescription,
ao.offence.subCategoryDescription as subCategoryDescription,
ao.date,
false,
ao.event.number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ data class Offence(
val id: String,
val code: String,
val description: String,
val mainCategoryDescription: String,
val subCategoryDescription: String,
val date: LocalDate?,
val main: Boolean,
val eventId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ fun CommunityManager.team() = Team(
)

fun CaseOffence.asOffence() =
Offence(id = if (main) "M$id" else "A$id", code, description, date, main, eventId, eventNumber)
Offence(
id = if (main) "M$id" else "A$id",
code,
description,
mainCategoryDescription,
subCategoryDescription,
date,
main,
eventId,
eventNumber
)

fun Registration.asRegistration() = uk.gov.justice.digital.hmpps.model.Registration(type.code, type.description, date)
fun Registration.asMappa() = MappaDetail(
Expand Down

0 comments on commit 0a3fbd7

Please sign in to comment.