Skip to content

Commit

Permalink
MAN-110 - update logic to allow the creation of appointments that ove…
Browse files Browse the repository at this point in the history
…rlap
  • Loading branch information
achimber-moj committed Nov 20, 2024
1 parent 3b0e74e commit 77acdfe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppointmentDetail>()

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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}")
}

Expand Down

0 comments on commit 77acdfe

Please sign in to comment.