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>

@Repository public interface BookingRepository extends org.springframework.data.jpa.repository.JpaRepository<Booking,Long>
Spring Data JPA repository for Booking entities. Provides standard CRUD operations via JpaRepository and custom query methods for filtering and conflict detection.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    findByEquipmentId(Long equipmentId)
    Finds all bookings for a specific equipment item.
    Finds all bookings with a specific status.
    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, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByEquipmentId

      List<Booking> findByEquipmentId(Long equipmentId)
      Finds all bookings for a specific equipment item.
      Parameters:
      equipmentId - the ID of the equipment item
      Returns:
      list of bookings for the given equipment
    • findByUserId

      List<Booking> findByUserId(Long userId)
      Finds all bookings created by a specific user.
      Parameters:
      userId - the ID of the user
      Returns:
      list of bookings created by the given user
    • findByStatus

      List<Booking> findByStatus(BookingStatus status)
      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 check
      dateFrom - the start of the requested date range
      dateTo - the end of the requested date range
      Returns:
      list of conflicting confirmed bookings (empty if no conflicts)