package org.hso.ecommerce.repos.booking; import java.util.List; import org.hso.ecommerce.entities.booking.Booking; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface BookingRepository extends JpaRepository { @Query("SELECT b FROM Booking b ORDER BY b.id DESC") List allBookingsReverseChronologically(); @Query("SELECT b FROM Booking b LEFT JOIN b.source s LEFT JOIN b.destination d WHERE s.isMainAccount = 1 OR d.isMainAccount = 1 ORDER BY b.id DESC") List mainBookingsReverseChronologically(); @Query("SELECT b FROM Booking b LEFT JOIN b.source s LEFT JOIN b.destination d WHERE s.isVATAccount = 1 OR d.isVATAccount = 1 ORDER BY b.id DESC") List vatBookingsReverseChronologically(); @Query("SELECT b FROM Booking b LEFT JOIN b.source s LEFT JOIN b.destination d WHERE s.userAccount.id = :customerId OR d.userAccount.id = :customerId ORDER BY b.id DESC") List customerBookingsReverseChronologically(long customerId); @Query("SELECT b FROM Booking b LEFT JOIN b.source s LEFT JOIN b.destination d WHERE s.supplierAccount.id = :supplierId OR d.supplierAccount.id = :supplierId ORDER BY b.id DESC") List supplierBookingsReverseChronologically(long supplierId); }