Interface BookingRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Booking,Long>, org.springframework.data.jpa.repository.JpaRepository<Booking, Long>, org.springframework.data.repository.ListCrudRepository<Booking, Long>, org.springframework.data.repository.ListPagingAndSortingRepository<Booking, Long>, org.springframework.data.repository.PagingAndSortingRepository<Booking, Long>, org.springframework.data.repository.query.QueryByExampleExecutor<Booking>, org.springframework.data.repository.Repository<Booking, Long>
-
Method Summary
Modifier and TypeMethodDescriptionfindByEquipmentId(Long equipmentId) Finds all bookings for a specific equipment item.findByStatus(BookingStatus status) Finds all bookings with a specific status.findByUserId(Long userId) Finds all bookings created by a specific user.findConflictingBookings(Long equipmentId, LocalDate dateFrom, LocalDate dateTo) Finds confirmed bookings for a given equipment item that overlap with the specified date range.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByEquipmentId
-
findByUserId
-
findByStatus
Finds all bookings with a specific status.- Parameters:
status- the booking status to filter by- Returns:
- list of bookings matching the given status
-
findConflictingBookings
@Query("SELECT booking FROM Booking booking WHERE booking.equipment.id = :equipmentId AND booking.status = 'CONFIRMED' AND booking.dateFrom <= :dateTo AND booking.dateTo >= :dateFrom") List<Booking> findConflictingBookings(@Param("equipmentId") Long equipmentId, @Param("dateFrom") LocalDate dateFrom, @Param("dateTo") LocalDate dateTo) Finds confirmed bookings for a given equipment item that overlap with the specified date range. Used by the service layer to enforce BR-02 (no overlapping bookings for the same item).The overlap logic treats both start and end dates as inclusive: a booking from 5 June to 10 June conflicts with one from 10 June to 15 June because 10 June falls within both ranges.
Only bookings with CONFIRMED status are considered; cancelled bookings are ignored.
- Parameters:
equipmentId- the ID of the equipment item to checkdateFrom- the start of the requested date rangedateTo- the end of the requested date range- Returns:
- list of conflicting confirmed bookings (empty if no conflicts)
-