diff --git a/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntTests.kt b/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntTests.kt index 7094cb24f4..2e6bd95989 100644 --- a/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntTests.kt +++ b/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CreateAppointmentIntTests.kt @@ -18,6 +18,7 @@ import uk.gov.justice.digital.hmpps.entity.AppointmentRepository import uk.gov.justice.digital.hmpps.test.CustomMatchers.isCloseTo import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken +import java.time.Duration import java.time.ZonedDateTime @AutoConfigureMockMvc @@ -41,7 +42,7 @@ internal class CreateAppointmentIntTests { CreateAppointment( CreateAppointment.Type.Accommodation, ZonedDateTime.now().plusDays(1), - ZonedDateTime.now().plusDays(1) + Duration.ofMinutes(30) ) ) ).andExpect(MockMvcResultMatchers.status().isNotFound) @@ -54,7 +55,7 @@ internal class CreateAppointmentIntTests { post("/appointments/${PersonGenerator.CREATE_APPOINTMENT.crn}") .withToken() .withJson( - CreateAppointment(CreateAppointment.Type.Health, start, start.plusMinutes(30)) + CreateAppointment(CreateAppointment.Type.Health, start, Duration.ofMinutes(30)) ) ).andExpect(MockMvcResultMatchers.status().isConflict) } @@ -66,7 +67,7 @@ internal class CreateAppointmentIntTests { post("/appointments/${PersonGenerator.CREATE_APPOINTMENT.crn}") .withToken() .withJson( - CreateAppointment(CreateAppointment.Type.Finance, start, start.minusSeconds(1)) + CreateAppointment(CreateAppointment.Type.Finance, start, Duration.ofMinutes(-1)) ) ).andExpect(MockMvcResultMatchers.status().isBadRequest) } @@ -76,7 +77,7 @@ internal class CreateAppointmentIntTests { val person = PersonGenerator.CREATE_APPOINTMENT val start = ZonedDateTime.now().plusDays(1) val notes = "Resettlement Passport Notes" - val create = CreateAppointment(CreateAppointment.Type.SkillsAndWork, start, start.plusHours(1), notes) + val create = CreateAppointment(CreateAppointment.Type.SkillsAndWork, start, Duration.ofHours(1), notes) mockMvc.perform( post("/appointments/${person.crn}") diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Appointment.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Appointment.kt index 407cf441d5..91270d061d 100644 --- a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Appointment.kt +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Appointment.kt @@ -1,11 +1,13 @@ package uk.gov.justice.digital.hmpps.api.model +import io.swagger.v3.oas.annotations.media.Schema import java.time.Duration import java.time.ZonedDateTime data class Appointment( val type: Type, val dateTime: ZonedDateTime, + @Schema(type = "string", format = "duration") val duration: Duration, val staff: Staff, val location: Location?, diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/CreateAppointment.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/CreateAppointment.kt index 8f8a604127..619e380963 100644 --- a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/CreateAppointment.kt +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/CreateAppointment.kt @@ -1,19 +1,25 @@ package uk.gov.justice.digital.hmpps.api.model import com.fasterxml.jackson.annotation.JsonIgnore +import io.swagger.v3.oas.annotations.media.Schema +import java.time.Duration import java.time.ZonedDateTime import java.util.* data class CreateAppointment( val type: Type, val start: ZonedDateTime, - val end: ZonedDateTime, + @Schema(type = "string", format = "duration") + val duration: Duration, val notes: String? = null, val uuid: UUID = UUID.randomUUID() ) { @JsonIgnore val urn = URN_PREFIX + uuid + @JsonIgnore + val end: ZonedDateTime = start.plus(duration) + enum class Type(val code: String) { Accommodation("RP1"), ThinkingAndBehaviour("RP2"), diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AppointmentService.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AppointmentService.kt index 0769742eab..ca1e04e0ae 100644 --- a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AppointmentService.kt +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AppointmentService.kt @@ -72,7 +72,8 @@ class AppointmentService( personId: Long, createAppointment: CreateAppointment ) { - if (!createAppointment.start.isBefore(createAppointment.end)) { + + if (createAppointment.duration.isNegative) { throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Appointment end time cannot be before start time.") } if (createAppointment.start.isAfter(ZonedDateTime.now()) && appointmentRepository.appointmentClashes(