Skip to content

Commit

Permalink
Change lostBed to voidBedspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad El Abdulla committed Jan 7, 2025
1 parent f5cb737 commit c20c305
Show file tree
Hide file tree
Showing 61 changed files with 813 additions and 812 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.UserAccessServic
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.UserService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1WithdrawableService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3BookingService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3LostBedService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3PremisesService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3VoidBedspaceService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ArrivalTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.BedDetailTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.BedSummaryTransformer
Expand All @@ -84,8 +84,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.PremisesTran
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.RoomTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.StaffMemberTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.TurnaroundTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedCancellationTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedsTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceCancellationTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspacesTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.extractEntityFromAuthorisableActionResult
import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.extractEntityFromCasResult
import java.time.LocalDate
Expand All @@ -102,12 +102,12 @@ class PremisesController(
private val offenderService: OffenderService,
private val bookingService: BookingService,
private val cas3BookingService: Cas3BookingService,
private val lostBedsService: Cas3LostBedService,
private val cas3VoidBedspaceService: Cas3VoidBedspaceService,
private val bedService: BedService,
private val premisesTransformer: PremisesTransformer,
private val premisesSummaryTransformer: PremisesSummaryTransformer,
private val bookingTransformer: BookingTransformer,
private val cas3LostBedsTransformer: Cas3LostBedsTransformer,
private val cas3VoidBedspacesTransformer: Cas3VoidBedspacesTransformer,
private val arrivalTransformer: ArrivalTransformer,
private val cancellationTransformer: CancellationTransformer,
private val confirmationTransformer: ConfirmationTransformer,
Expand All @@ -117,7 +117,7 @@ class PremisesController(
private val staffMemberService: StaffMemberService,
private val roomService: RoomService,
private val roomTransformer: RoomTransformer,
private val cas3LostBedCancellationTransformer: Cas3LostBedCancellationTransformer,
private val cas3VoidBedspaceCancellationTransformer: Cas3VoidBedspaceCancellationTransformer,
private val turnaroundTransformer: TurnaroundTransformer,
private val bedSummaryTransformer: BedSummaryTransformer,
private val bedDetailTransformer: BedDetailTransformer,
Expand Down Expand Up @@ -690,7 +690,7 @@ class PremisesController(
val premises = premisesService.getPremises(premisesId)
?: throw NotFoundProblem(premisesId, "Premises")

if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) {
if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) {
throw ForbiddenProblem()
}

Expand All @@ -707,9 +707,9 @@ class PremisesController(
bedId = body.bedId,
)

val lostBeds = extractResultEntityOrThrow(result)
val voidBedspaces = extractResultEntityOrThrow(result)

return ResponseEntity.ok(cas3LostBedsTransformer.transformJpaToApi(lostBeds))
return ResponseEntity.ok(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspaces))
}

override fun premisesPremisesIdLostBedsGet(premisesId: UUID): ResponseEntity<List<LostBed>> {
Expand All @@ -718,13 +718,13 @@ class PremisesController(
val premises = cas3PremisesService.getPremises(premisesId)
?: throw NotFoundProblem(premisesId, "Premises")

val lostBeds = lostBedsService.getActiveLostBedsForPremisesId(premisesId)
val voidBedspaces = cas3VoidBedspaceService.getActiveVoidBedspacesForPremisesId(premisesId)

if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) {
if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) {
throw ForbiddenProblem()
}

return ResponseEntity.ok(lostBeds.map(cas3LostBedsTransformer::transformJpaToApi))
return ResponseEntity.ok(voidBedspaces.map(cas3VoidBedspacesTransformer::transformJpaToApi))
}

override fun premisesPremisesIdLostBedsLostBedIdGet(premisesId: UUID, lostBedId: UUID): ResponseEntity<LostBed> {
Expand All @@ -733,14 +733,14 @@ class PremisesController(
val premises = cas3PremisesService.getPremises(premisesId)
?: throw NotFoundProblem(premisesId, "Premises")

if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) {
if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) {
throw ForbiddenProblem()
}

val lostBed = premises.lostBeds.firstOrNull { it.id == lostBedId }
val voidBedspace = premises.voidBedspaces.firstOrNull { it.id == lostBedId }
?: throw NotFoundProblem(lostBedId, "LostBed")

return ResponseEntity.ok(cas3LostBedsTransformer.transformJpaToApi(lostBed))
return ResponseEntity.ok(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspace))
}

override fun premisesPremisesIdLostBedsLostBedIdPut(
Expand All @@ -751,16 +751,16 @@ class PremisesController(
throwIfRequestIsForApprovedPremises("PUT /cas1/premises/$premisesId/lost-beds/$lostBedId")

val premises = cas3PremisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises")
val lostBed = premises.lostBeds.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "LostBed")
val voidBedspace = premises.voidBedspaces.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "VoidBedspace")

if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) {
if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) {
throw ForbiddenProblem()
}

throwIfBookingDatesConflict(body.startDate, body.endDate, null, lostBed.bed.id)
throwIfVoidBedspaceDatesConflict(body.startDate, body.endDate, lostBedId, lostBed.bed.id)
throwIfBookingDatesConflict(body.startDate, body.endDate, null, voidBedspace.bed.id)
throwIfVoidBedspaceDatesConflict(body.startDate, body.endDate, lostBedId, voidBedspace.bed.id)

val updateLostBedResult = cas3PremisesService
val updateVoidBedspaceResult = cas3PremisesService
.updateVoidBedspaces(
lostBedId,
body.startDate,
Expand All @@ -770,13 +770,13 @@ class PremisesController(
body.notes,
)

val validationResult = when (updateLostBedResult) {
is AuthorisableActionResult.NotFound -> throw NotFoundProblem(lostBedId, "LostBed")
val validationResult = when (updateVoidBedspaceResult) {
is AuthorisableActionResult.NotFound -> throw NotFoundProblem(lostBedId, "VoidBedspace")
is AuthorisableActionResult.Unauthorised -> throw ForbiddenProblem()
is AuthorisableActionResult.Success -> updateLostBedResult.entity
is AuthorisableActionResult.Success -> updateVoidBedspaceResult.entity
}

val updatedLostBed = when (validationResult) {
val updatedVoidBedspace = when (validationResult) {
is ValidatableActionResult.GeneralValidationError -> throw BadRequestProblem(errorDetail = validationResult.message)
is ValidatableActionResult.FieldValidationError -> throw BadRequestProblem(invalidParams = validationResult.validationMessages)
is ValidatableActionResult.ConflictError -> throw ConflictProblem(
Expand All @@ -787,7 +787,7 @@ class PremisesController(
is ValidatableActionResult.Success -> validationResult.entity
}

return ResponseEntity.ok(cas3LostBedsTransformer.transformJpaToApi(updatedLostBed))
return ResponseEntity.ok(cas3VoidBedspacesTransformer.transformJpaToApi(updatedVoidBedspace))
}

override fun premisesPremisesIdLostBedsLostBedIdCancellationsPost(
Expand All @@ -798,9 +798,9 @@ class PremisesController(
throwIfRequestIsForApprovedPremises("POST /cas1/premises/$premisesId/lost-beds/$lostBedId/cancellations")

val premises = cas3PremisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises")
val voidBedspace = premises.lostBeds.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "LostBed")
val voidBedspace = premises.voidBedspaces.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "VoidBedspace")

if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) {
if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) {
throw ForbiddenProblem()
}

Expand All @@ -820,7 +820,7 @@ class PremisesController(
is ValidatableActionResult.Success -> cancelVoidBedspaceResult.entity
}

return ResponseEntity.ok(cas3LostBedCancellationTransformer.transformJpaToApi(cancellation))
return ResponseEntity.ok(cas3VoidBedspaceCancellationTransformer.transformJpaToApi(cancellation))
}

override fun premisesPremisesIdStaffGet(premisesId: UUID): ResponseEntity<List<StaffMember>> {
Expand Down Expand Up @@ -1059,7 +1059,7 @@ class PremisesController(
thisEntityId: UUID?,
bedId: UUID,
) {
bookingService.getLostBedWithConflictingDates(startDate, endDate, thisEntityId, bedId)?.let {
bookingService.getVoidBedspaceWithConflictingDates(startDate, endDate, thisEntityId, bedId)?.let {
throw ConflictProblem(
it.id,
"A Lost Bed already exists for dates from ${it.startDate} to ${it.endDate} which overlaps with the desired dates",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.NonArrivalRea
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationDeliveryUnitRepository
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionRepository
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ReferralRejectionReasonRepository
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonRepository
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonRepository
import uk.gov.justice.digital.hmpps.approvedpremisesapi.problem.ForbiddenProblem
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ApAreaTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.CancellationReasonTransformer
Expand All @@ -40,7 +40,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.NonArrivalRe
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ProbationDeliveryUnitTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ProbationRegionTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ReferralRejectionReasonTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedReasonTransformer
import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceReasonTransformer
import java.util.UUID

@Service
Expand All @@ -49,7 +49,7 @@ class ReferenceDataController(
private val moveOnCategoryRepository: MoveOnCategoryRepository,
private val destinationProviderRepository: DestinationProviderRepository,
private val cancellationReasonRepository: CancellationReasonRepository,
private val cas3LostBedReasonRepository: Cas3LostBedReasonRepository,
private val cas3VoidBedspaceReasonRepository: Cas3VoidBedspaceReasonRepository,
private val localAuthorityAreaRepository: LocalAuthorityAreaRepository,
private val characteristicRepository: CharacteristicRepository,
private val probationRegionRepository: ProbationRegionRepository,
Expand All @@ -60,7 +60,7 @@ class ReferenceDataController(
private val moveOnCategoryTransformer: MoveOnCategoryTransformer,
private val destinationProviderTransformer: DestinationProviderTransformer,
private val cancellationReasonTransformer: CancellationReasonTransformer,
private val cas3LostBedReasonTransformer: Cas3LostBedReasonTransformer,
private val cas3VoidBedspaceReasonTransformer: Cas3VoidBedspaceReasonTransformer,
private val localAuthorityAreaTransformer: LocalAuthorityAreaTransformer,
private val characteristicTransformer: CharacteristicTransformer,
private val probationRegionTransformer: ProbationRegionTransformer,
Expand Down Expand Up @@ -144,12 +144,12 @@ class ReferenceDataController(
}

override fun referenceDataLostBedReasonsGet(xServiceName: ServiceName?): ResponseEntity<List<LostBedReason>> {
val lostBedReasons = when (xServiceName == ServiceName.temporaryAccommodation) {
true -> cas3LostBedReasonRepository.findAllByServiceScope(xServiceName.value)
val voidBedspaceReasons = when (xServiceName == ServiceName.temporaryAccommodation) {
true -> cas3VoidBedspaceReasonRepository.findAllByServiceScope(xServiceName.value)
false -> throw ForbiddenProblem()
}

return ResponseEntity.ok(lostBedReasons.map(cas3LostBedReasonTransformer::transformJpaToApi))
return ResponseEntity.ok(voidBedspaceReasons.map(cas3VoidBedspaceReasonTransformer::transformJpaToApi))
}

override fun referenceDataProbationRegionsGet(): ResponseEntity<List<ProbationRegion>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.controller.generateStrea
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserPermission
import uk.gov.justice.digital.hmpps.approvedpremisesapi.problem.BadRequestProblem
import uk.gov.justice.digital.hmpps.approvedpremisesapi.problem.NotAllowedProblem
import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.LostBedReportProperties
import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.VoidBedspaceReportProperties
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.UserAccessService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1ReportService
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1ReportService.MonthSpecificReportParams
Expand Down Expand Up @@ -75,7 +75,7 @@ class Cas1ReportsController(
contentType = ContentType.XLSX,
fileName = createCas1ReportName("lost-beds", year, month, ContentType.XLSX),
) { outputStream ->
cas1ReportService.createLostBedReport(LostBedReportProperties(xServiceName, null, year, month), outputStream)
cas1ReportService.createLostBedReport(VoidBedspaceReportProperties(xServiceName, null, year, month), outputStream)
}
Cas1ReportName.outOfServiceBeds -> return generateStreamingResponse(
contentType = ContentType.XLSX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.BookingStatus
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.PropertyStatus
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity
import java.time.LocalDate
import java.util.UUID

Expand Down Expand Up @@ -242,7 +242,7 @@ abstract class PremisesEntity(
@OneToMany(mappedBy = "premises")
val bookings: MutableList<BookingEntity>,
@OneToMany(mappedBy = "premises")
val lostBeds: MutableList<Cas3LostBedsEntity>,
val voidBedspaces: MutableList<Cas3VoidBedspacesEntity>,
@OneToMany(mappedBy = "premises")
val rooms: MutableList<RoomEntity>,
@ManyToMany
Expand Down Expand Up @@ -275,7 +275,7 @@ class ApprovedPremisesEntity(
probationRegion: ProbationRegionEntity,
localAuthorityArea: LocalAuthorityAreaEntity,
bookings: MutableList<BookingEntity>,
lostBeds: MutableList<Cas3LostBedsEntity>,
lostBeds: MutableList<Cas3VoidBedspacesEntity>,
var apCode: String,
var qCode: String,
rooms: MutableList<RoomEntity>,
Expand Down Expand Up @@ -337,7 +337,7 @@ class TemporaryAccommodationPremisesEntity(
probationRegion: ProbationRegionEntity,
localAuthorityArea: LocalAuthorityAreaEntity?,
bookings: MutableList<BookingEntity>,
lostBeds: MutableList<Cas3LostBedsEntity>,
lostBeds: MutableList<Cas3VoidBedspacesEntity>,
rooms: MutableList<RoomEntity>,
characteristics: MutableList<CharacteristicEntity>,
status: PropertyStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import java.util.Objects
import java.util.UUID

@Repository
interface Cas3LostBedCancellationRepository : JpaRepository<Cas3LostBedCancellationEntity, UUID>
interface Cas3VoidBedspaceCancellationRepository : JpaRepository<Cas3VoidBedspaceCancellationEntity, UUID>

@Entity
@Table(name = "lost_bed_cancellations")
data class Cas3LostBedCancellationEntity(
data class Cas3VoidBedspaceCancellationEntity(
@Id
val id: UUID,
val createdAt: OffsetDateTime,
val notes: String?,
@OneToOne
@JoinColumn(name = "lost_bed_id")
val lostBed: Cas3LostBedsEntity,
val voidBedspace: Cas3VoidBedspacesEntity,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Cas3LostBedCancellationEntity) return false
if (other !is Cas3VoidBedspaceCancellationEntity) return false

if (id != other.id) return false
if (notes != other.notes) return false
Expand All @@ -38,5 +38,5 @@ data class Cas3LostBedCancellationEntity(

override fun hashCode() = Objects.hash(notes, createdAt)

override fun toString() = "Cas3LostBedCancellationEntity:$id"
override fun toString() = "Cas3VoidBedspaceCancellationEntity:$id"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import org.springframework.stereotype.Repository
import java.util.UUID

@Repository
interface Cas3LostBedReasonRepository : JpaRepository<Cas3LostBedReasonEntity, UUID> {
@Query("SELECT l FROM Cas3LostBedReasonEntity l WHERE l.serviceScope = :serviceName OR l.serviceScope = '*'")
fun findAllByServiceScope(serviceName: String): List<Cas3LostBedReasonEntity>
interface Cas3VoidBedspaceReasonRepository : JpaRepository<Cas3VoidBedspaceReasonEntity, UUID> {
@Query("SELECT l FROM Cas3VoidBedspaceReasonEntity l WHERE l.serviceScope = :serviceName OR l.serviceScope = '*'")
fun findAllByServiceScope(serviceName: String): List<Cas3VoidBedspaceReasonEntity>
}

@Entity
@Table(name = "lost_bed_reasons")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
data class Cas3LostBedReasonEntity(
data class Cas3VoidBedspaceReasonEntity(
@Id
val id: UUID,
val name: String,
val isActive: Boolean,
val serviceScope: String,
) {
override fun toString() = "Cas3LostBedReasonEntity:$id"
override fun toString() = "Cas3VoidBedspaceReasonEntity:$id"
}
Loading

0 comments on commit c20c305

Please sign in to comment.