diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntegrationTests.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntegrationTests.kt index 90c3700d0b..cc82c958f7 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntegrationTests.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntegrationTests.kt @@ -196,9 +196,32 @@ class CreateAppointmentIntegrationTests { .andExpect(MockMvcResultMatchers.status().isConflict) .andExpect(jsonPath("$.message", equalTo(errorMsg))) - val appointments = appointmentRepository.findAllById(response.appointments.map { it.id }) + val overlapAppointment = CreateAppointment( + Companion.user, + CreateAppointment.Type.HomeVisitToCaseNS, + ZonedDateTime.of(LocalDate.now().plusDays(1), LocalTime.NOON, EuropeLondon), + ZonedDateTime.of(LocalDate.now().plusDays(1), LocalTime.NOON.plusHours(1), EuropeLondon), + numberOfAppointments = 3, + eventId = PersonGenerator.EVENT_1.id, + uuid = UUID.randomUUID(), + createOverlappingAppointment = true + ) + + val overlapAppointmentResponse = mockMvc.perform( + post("/appointment/${person.crn}") + .withToken() + .withJson(overlapAppointment)) + .andDo(print()) + .andExpect(MockMvcResultMatchers.status().isCreated) + .andReturn().response.contentAsJson() + + val appointments = appointmentRepository.findAllById(response.appointments.map { it.id }) + appointmentRepository.findAllById(overlapAppointmentResponse.appointments.map { it.id }) + + assertThat(appointments.size, equalTo(6)) appointmentRepository.deleteAll(appointments) + } + companion object { private val user = User(STAFF_USER_1.username, TEAM.description) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/appointment/CreateAppointment.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/appointment/CreateAppointment.kt index e0fdba1857..059fad9c00 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/appointment/CreateAppointment.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/appointment/CreateAppointment.kt @@ -13,9 +13,10 @@ data class CreateAppointment( val numberOfAppointments: Int = 1, val eventId: Long, val uuid: UUID, + val createOverlappingAppointment: Boolean = false, val requirementId: Long? = null, val licenceConditionId: Long? = null, - val until: ZonedDateTime? = null + val until: ZonedDateTime? = null, ) { @JsonIgnore val urn = URN_PREFIX + uuid diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceAppointmentService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceAppointmentService.kt index 8b07bd9b59..d34e68049c 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceAppointmentService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceAppointmentService.kt @@ -69,6 +69,7 @@ class SentenceAppointmentService( createAppointment.numberOfAppointments, createAppointment.eventId, if (i == 0) createAppointment.uuid else UUID.randomUUID(), //needs to be a unique value + createAppointment.createOverlappingAppointment, createAppointment.requirementId, createAppointment.licenceConditionId, createAppointment.until @@ -92,7 +93,7 @@ class SentenceAppointmentService( } else null } - if (overlappingAppointments.isNotEmpty()) { + if (!createAppointment.createOverlappingAppointment && overlappingAppointments.isNotEmpty()) { throw ConflictException("Appointment(s) conflicts with an existing future appointment ${objectMapper.writeValueAsString(overlappingAppointments)}") }