Skip to content

Commit

Permalink
MAN-28 - update api
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Oct 21, 2024
1 parent 88e991c commit 7b71e0b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import uk.gov.justice.digital.hmpps.service.toSummary
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
import java.time.LocalDate
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceCondition
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LC_WITH_NOTES
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_MAIN_CAT
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_SUB_CAT

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Expand Down Expand Up @@ -50,13 +53,22 @@ class LicenceConditionIntegrationTest {
fun `note not found`() {
val response = mockMvc
.perform(
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LicenceConditionGenerator.LC_WITH_NOTES.id}/note/7")
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LC_WITH_NOTES.id}/note/7")
.withToken()
)
.andExpect(MockMvcResultMatchers.status().isOk)
.andReturn().response.contentAsJson<LicenceConditionNoteDetail>()

val expected = LicenceConditionNoteDetail(PersonGenerator.OVERVIEW.toSummary())
val expected = LicenceConditionNoteDetail(
PersonGenerator.OVERVIEW.toSummary(),
LicenceCondition(
LC_WITH_NOTES.id,
LIC_COND_MAIN_CAT.description,
LIC_COND_SUB_CAT.description,
LocalDate.now().minusDays(7),
LocalDate.now()
)
)

assertEquals(expected, response)
}
Expand All @@ -65,22 +77,27 @@ class LicenceConditionIntegrationTest {
fun `get note for licence condition`() {
val response = mockMvc
.perform(
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LicenceConditionGenerator.LC_WITH_NOTES.id}/note/0")
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LC_WITH_NOTES.id}/note/0")
.withToken()
)
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk)
.andReturn().response.contentAsJson<LicenceConditionNoteDetail>()

val expected = LicenceConditionNoteDetail(
PersonGenerator.OVERVIEW.toSummary(),
LicenceConditionNote(
LicenceCondition(
LC_WITH_NOTES.id,
LIC_COND_MAIN_CAT.description,
LIC_COND_SUB_CAT.description,
LocalDate.now().minusDays(7),
LocalDate.now(),
note = LicenceConditionNote(
0,
"CVL Service",
LocalDate.of(2024, 4, 22),
"""
${LicenceConditionGenerator.LONG_NOTE}
""".trimIndent() + System.lineSeparator()
""".trimIndent() + System.lineSeparator())
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
import java.time.LocalDate
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_MAIN_CAT
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_SUB_CAT
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Expand All @@ -50,7 +49,6 @@ class SentenceIntegrationTest {
fun `get active sentences`() {
val response = mockMvc
.perform(MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}").withToken())
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk)
.andReturn().response.contentAsJson<SentenceOverview>()

Expand Down Expand Up @@ -157,6 +155,7 @@ class SentenceIntegrationTest {
LC_WITHOUT_NOTES.id,
LIC_COND_MAIN_CAT.description,
imposedReleasedDate = LocalDate.now().minusDays(14),
notes = listOf()
),
LicenceCondition(
LC_WITH_NOTES_WITHOUT_ADDED_BY.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ data class LicenceCondition(
val subTypeDescription: String? = null,
val imposedReleasedDate: LocalDate,
val actualStartDate: LocalDate? = null,
val notes: List<LicenceConditionNote> = listOf()
val notes: List<LicenceConditionNote>? = null,
val note: LicenceConditionNote? = null
)

data class LicenceConditionNote(
Expand All @@ -22,5 +23,5 @@ data class LicenceConditionNote(

data class LicenceConditionNoteDetail(
val personSummary: PersonSummary,
val licenceConditionNote: LicenceConditionNote? = null
val licenceCondition: LicenceCondition? = null
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.digital.hmpps.service

import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceCondition
import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceConditionNote
import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceConditionNoteDetail
import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter
Expand All @@ -23,17 +24,32 @@ class LicenceConditionService(

return LicenceConditionNoteDetail(
person.toSummary(),
licenceCondition?.toLicenceConditionNote(false)?.let {
when {
it.size > noteId -> it[noteId]
else -> null
}
}
licenceCondition?.toLicenceConditionSingleNote(noteId, false)
)

}
}

fun EntityLicenceCondition.toLicenceCondition() =
LicenceCondition(
id,
mainCategory.description,
subCategory?.description,
imposedReleasedDate,
actualStartDate,
toLicenceConditionNote(true)
)

fun EntityLicenceCondition.toLicenceConditionSingleNote(noteId: Int, truncateNote: Boolean) =
LicenceCondition(
id,
mainCategory.description,
subCategory?.description,
imposedReleasedDate,
actualStartDate,
note = toLicenceConditionNote(truncateNote).elementAtOrNull(noteId)
)

fun EntityLicenceCondition.toLicenceConditionNote(truncateNote: Boolean): List<LicenceConditionNote> {

return notes?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.time.Duration
import java.time.LocalDate
import kotlin.time.toKotlinDuration
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AdditionalSentence as ExtraSentence
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition as EntityLicenceCondition

@Service
class SentenceService(
Expand Down Expand Up @@ -77,16 +76,6 @@ class SentenceService(
} ?: emptyList(),
)

fun EntityLicenceCondition.toLicenceCondition() =
LicenceCondition(
id,
mainCategory.description,
subCategory?.description,
imposedReleasedDate,
actualStartDate,
toLicenceConditionNote(true)
)


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

0 comments on commit 7b71e0b

Please sign in to comment.