Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PI-2007 update swagger to display duration correctly and use duration on create
  • Loading branch information
anthony-britton-moj authored Mar 14, 2024
1 parent e8394b2 commit 8a9f489
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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?,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8a9f489

Please sign in to comment.