Skip to content

Commit

Permalink
Change lost_beds table name to cas3_void_bedspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad El Abdulla committed Jan 8, 2025
1 parent f30707c commit 51d6b98
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ const val BED_SUMMARY_QUERY =
and non_arrival IS NULL
) > 0 as bedBooked,
(
select count(lost_bed.id)
from lost_beds lost_bed
select count(void_bedspace.id)
from cas3_void_bedspaces void_bedspace
left join lost_bed_cancellations cancellation
on lost_bed.id = cancellation.lost_bed_id
where lost_bed.bed_id = b.id
and lost_bed.start_date <= CURRENT_DATE
and lost_bed.end_date >= CURRENT_DATE
on void_bedspace.id = cancellation.lost_bed_id
where void_bedspace.bed_id = b.id
and void_bedspace.start_date <= CURRENT_DATE
and void_bedspace.end_date >= CURRENT_DATE
and cancellation IS NULL
) > 0 as bedOutOfService
from beds b
join rooms r on b.room_id = r.id
join rooms r on b.room_id = r.id
"""

@NamedNativeQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface Cas3VoidBedspacesRepository : JpaRepository<Cas3VoidBedspacesEntity, U

@SuppressWarnings("LongParameterList")
@Entity
@Table(name = "lost_beds")
@Table(name = "cas3_void_bedspaces")
class Cas3VoidBedspacesEntity(
@Id
val id: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class BedSearchRepository(private val namedParameterJdbcTemplate: NamedParameter
NOT EXISTS (SELECT bb.bed_id FROM BookedBedspaces bb
WHERE bb.bed_id = b.id
) AND
NOT EXISTS (SELECT lostbeds.bed_id FROM lost_beds lostbeds
LEFT JOIN lost_bed_cancellations lostbeds_cancel ON lostbeds_cancel.lost_bed_id = lostbeds.id
NOT EXISTS (SELECT void_bedspace.bed_id FROM cas3_void_bedspaces void_bedspace
LEFT JOIN lost_bed_cancellations lostbeds_cancel ON lostbeds_cancel.lost_bed_id = void_bedspace.id
WHERE
lostbeds.bed_id = b.id AND
(lostbeds.start_date, lostbeds.end_date) OVERLAPS (:start_date, :end_date) AND
void_bedspace.bed_id = b.id AND
(void_bedspace.start_date, void_bedspace.end_date) OVERLAPS (:start_date, :end_date) AND
lostbeds_cancel.id IS NULL
) AND
#OPTIONAL_FILTERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ interface BedUtilisationReportRepository : JpaRepository<BedEntity, UUID> {
"""
SELECT
CAST(b.id AS VARCHAR) AS bedId,
lb.start_date AS startDate,
lb.end_date AS endDate,
vb.start_date AS startDate,
vb.end_date AS endDate,
CAST(lbc.id AS VARCHAR) AS cancellationId
From lost_beds lb
LEFT JOIN beds b ON lb.bed_id = b.id
From cas3_void_bedspaces vb
LEFT JOIN beds b ON vb.bed_id = b.id
LEFT JOIN rooms r ON b.room_id = r.id
LEFT JOIN premises p ON r.premises_id = p.id
LEFT JOIN lost_bed_cancellations lbc ON lb.id = lbc.lost_bed_id
LEFT JOIN lost_bed_cancellations lbc ON vb.id = lbc.lost_bed_id
WHERE
p.service = 'temporary-accommodation'
AND (CAST(:probationRegionId AS UUID) IS NULL OR p.probation_region_id = :probationRegionId)
AND lb.start_date <= :endDate AND lb.end_date >= :startDate
AND vb.start_date <= :endDate AND vb.end_date >= :startDate
AND lbc.id is NULL
ORDER BY lb.id
ORDER BY vb.id
""",
nativeQuery = true,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE lost_beds RENAME TO cas3_void_bedspaces;

0 comments on commit 51d6b98

Please sign in to comment.