From e2099aee49345fdea2e03f766d77d96c94dabbac Mon Sep 17 00:00:00 2001 From: rmccormack Date: Fri, 21 Feb 2025 13:30:31 +0000 Subject: [PATCH 1/2] DST-18162 : ktLint --- .../entity/BreachNoticeEntity.kt | 6 +++--- .../hmpps/breachnoticeapi/model/BreachNotice.kt | 4 +++- .../model/BreachNoticeDetails.kt | 4 +++- .../service/BreachNoticeService.kt | 17 +++++++++++++---- .../migration/V1_1__next_appointment_fields.sql | 6 ++++++ .../integration/BreachNoticeCrudTests.kt | 4 ++-- 6 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/db/migration/V1_1__next_appointment_fields.sql diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/entity/BreachNoticeEntity.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/entity/BreachNoticeEntity.kt index 354863e..9584f25 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/entity/BreachNoticeEntity.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/entity/BreachNoticeEntity.kt @@ -40,9 +40,7 @@ data class BreachNoticeEntity( var nextAppointmentDate: LocalDateTime? = null, var nextAppointmentLocation: String? = null, var nextAppointmentOfficer: String? = null, - @OneToOne(cascade = [CascadeType.ALL], orphanRemoval = true) - @JoinColumn(name = "next_appointment_contact_id", unique = true) - var nextAppointmentContact: BreachNoticeContactEntity? = null, + var nextAppointmentId: Long? = null, var completedDate: LocalDateTime? = null, @CreatedBy var createdByUser: String? = null, @@ -68,4 +66,6 @@ data class BreachNoticeEntity( val breachNoticeContactList: List = emptyList(), @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true, mappedBy = "breachNotice") val breachNoticeRequirementList: List = emptyList(), + var optionalNumberChecked: Boolean? = null, + var optionalNumber: String? = null, ) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNotice.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNotice.kt index cf75802..868a7b2 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNotice.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNotice.kt @@ -23,7 +23,7 @@ data class BreachNotice( val nextAppointmentDate: LocalDateTime? = null, val nextAppointmentLocation: String? = null, val nextAppointmentOfficer: String? = null, - val nextAppointmentContact: BreachNoticeContact? = null, + val nextAppointmentId: Long? = null, val completedDate: LocalDateTime? = null, val offenderAddress: Address? = null, val replyAddress: Address? = null, @@ -37,4 +37,6 @@ data class BreachNotice( val breachNoticeContactList: List = emptyList(), @field:JsonSetter(nulls = Nulls.AS_EMPTY) val breachNoticeRequirementList: List = emptyList(), + val optionalNumberChecked: Boolean? = null, + val optionalNumber: String? = null, ) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNoticeDetails.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNoticeDetails.kt index 7157c66..781c8b3 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNoticeDetails.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/model/BreachNoticeDetails.kt @@ -25,7 +25,7 @@ data class BreachNoticeDetails( val nextAppointmentDate: LocalDateTime? = null, val nextAppointmentLocation: String? = null, val nextAppointmentOfficer: String? = null, - val nextAppointmentContact: BreachNoticeContact? = null, + val nextAppointmentId: Long? = null, val completedDate: LocalDateTime? = null, val offenderAddress: Address? = null, val replyAddress: Address? = null, @@ -39,4 +39,6 @@ data class BreachNoticeDetails( val breachNoticeContactList: List = emptyList(), @field:JsonSetter(nulls = Nulls.AS_EMPTY) val breachNoticeRequirementList: List = emptyList(), + val optionalNumberChecked: Boolean? = null, + val optionalNumber: String? = null, ) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt index df3555a..658f253 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt @@ -70,7 +70,7 @@ class BreachNoticeService( nextAppointmentDate = nextAppointmentDate, nextAppointmentLocation = nextAppointmentLocation, nextAppointmentOfficer = nextAppointmentOfficer, - nextAppointmentContact = nextAppointmentContact?.toEntity(existingEntity.nextAppointmentContact), + nextAppointmentId = nextAppointmentId, completedDate = completedDate, offenderAddress = offenderAddress?.toEntity(existingEntity.offenderAddress), replyAddress = replyAddress?.toEntity(existingEntity.replyAddress), @@ -98,6 +98,9 @@ class BreachNoticeService( breachNotice.breachNoticeContactList.forEach { it.breachNotice = breachNotice } breachNotice.breachNoticeRequirementList.forEach { it.breachNotice = breachNotice } } ?: BreachNoticeEntity( + optionalNumberChecked = optionalNumberChecked, + optionalNumber = optionalNumber, + ) ?: BreachNoticeEntity( crn = crn, titleAndFullName = titleAndFullName, dateOfLetter = dateOfLetter, @@ -115,7 +118,7 @@ class BreachNoticeService( nextAppointmentDate = nextAppointmentDate, nextAppointmentLocation = nextAppointmentLocation, nextAppointmentOfficer = nextAppointmentOfficer, - nextAppointmentContact = nextAppointmentContact?.toEntity(), + nextAppointmentId = nextAppointmentId, completedDate = completedDate, offenderAddress = offenderAddress?.toEntity(), replyAddress = replyAddress?.toEntity(), @@ -125,6 +128,8 @@ class BreachNoticeService( nextAppointmentSaved = nextAppointmentSaved, useDefaultAddress = useDefaultAddress, useDefaultReplyAddress = useDefaultReplyAddress, + optionalNumberChecked = optionalNumberChecked, + optionalNumber = optionalNumber, breachNoticeRequirementList = breachNoticeRequirementList.map { it.toEntity() }, breachNoticeContactList = breachNoticeContactList.map { it.toEntity() }, ) @@ -148,7 +153,7 @@ class BreachNoticeService( nextAppointmentDate = nextAppointmentDate, nextAppointmentLocation = nextAppointmentLocation, nextAppointmentOfficer = nextAppointmentOfficer, - nextAppointmentContact = nextAppointmentContact?.toModel(), + nextAppointmentId = nextAppointmentId, completedDate = completedDate, offenderAddress = offenderAddress?.toModel(), replyAddress = replyAddress?.toModel(), @@ -160,6 +165,8 @@ class BreachNoticeService( useDefaultReplyAddress = useDefaultReplyAddress, breachNoticeContactList = breachNoticeContactList.map { it.toModel() }, breachNoticeRequirementList = breachNoticeRequirementList.map { it.toModel() }, + optionalNumberChecked = optionalNumberChecked, + optionalNumber = optionalNumber, ) fun getBreachNoticeById(uuid: UUID) = breachNoticeRepository.findById(uuid).getOrNull()?.let { @@ -182,6 +189,7 @@ class BreachNoticeService( nextAppointmentDate = it.nextAppointmentDate, nextAppointmentLocation = it.nextAppointmentLocation, nextAppointmentOfficer = it.nextAppointmentOfficer, + nextAppointmentId = it.nextAppointmentId, completedDate = it.completedDate, offenderAddress = it.offenderAddress?.toModel(), replyAddress = it.replyAddress?.toModel(), @@ -193,7 +201,8 @@ class BreachNoticeService( useDefaultReplyAddress = it.useDefaultReplyAddress, breachNoticeContactList = it.breachNoticeContactList.map { it.toModel() }, breachNoticeRequirementList = it.breachNoticeRequirementList.map { it.toModel() }, - + optionalNumberChecked = it.optionalNumberChecked, + optionalNumber = it.optionalNumber, ) } diff --git a/src/main/resources/db/migration/V1_1__next_appointment_fields.sql b/src/main/resources/db/migration/V1_1__next_appointment_fields.sql new file mode 100644 index 0000000..9a74e02 --- /dev/null +++ b/src/main/resources/db/migration/V1_1__next_appointment_fields.sql @@ -0,0 +1,6 @@ +ALTER TABLE public.breach_notice DROP CONSTRAINT xfk1_breach_notice_contact; +ALTER TABLE public.breach_notice DROP COLUMN next_appointment_contact_id; +ALTER TABLE public.breach_notice ADD optional_number_checked boolean NULL; +ALTER TABLE public.breach_notice ADD optional_number varchar(255) NULL; +ALTER TABLE public.breach_notice ADD next_appointment_id integer NULL; + diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/integration/BreachNoticeCrudTests.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/integration/BreachNoticeCrudTests.kt index b8aafce..1757dfd 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/integration/BreachNoticeCrudTests.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/integration/BreachNoticeCrudTests.kt @@ -64,7 +64,7 @@ class BreachNoticeCrudTests : IntegrationTestBase() { nextAppointmentDate = LocalDateTime.now(), nextAppointmentLocation = "NXT_LOCATION", nextAppointmentOfficer = "APPT_OFFICER", - nextAppointmentContact = null, + nextAppointmentId = null, completedDate = LocalDateTime.now(), offenderAddress = Address( addressId = 25, @@ -143,7 +143,7 @@ class BreachNoticeCrudTests : IntegrationTestBase() { nextAppointmentDate = LocalDateTime.now(), nextAppointmentLocation = "NXT_LOCATION", nextAppointmentOfficer = "APPT_OFFICER", - nextAppointmentContact = null, + nextAppointmentId = null, completedDate = LocalDateTime.now(), offenderAddress = Address( addressId = 25, From 673edb90beec1bfad6ffd45fca86585808b9627d Mon Sep 17 00:00:00 2001 From: rmccormack Date: Fri, 21 Feb 2025 14:16:23 +0000 Subject: [PATCH 2/2] BR-34 --- .../hmpps/breachnoticeapi/service/BreachNoticeService.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt index 658f253..4d78bf8 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/breachnoticeapi/service/BreachNoticeService.kt @@ -98,9 +98,6 @@ class BreachNoticeService( breachNotice.breachNoticeContactList.forEach { it.breachNotice = breachNotice } breachNotice.breachNoticeRequirementList.forEach { it.breachNotice = breachNotice } } ?: BreachNoticeEntity( - optionalNumberChecked = optionalNumberChecked, - optionalNumber = optionalNumber, - ) ?: BreachNoticeEntity( crn = crn, titleAndFullName = titleAndFullName, dateOfLetter = dateOfLetter,