package edu.gjoko.schedlr.repositories; import edu.gjoko.schedlr.entity.Appointment; import edu.gjoko.schedlr.entity.Business; import edu.gjoko.schedlr.entity.Stakeholder; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.time.LocalDateTime; import java.util.List; @Repository public interface AppointmentRepository extends JpaRepository { List getAppointmentsByBusiness(Business business); List getAppointmentsByCustomer(Stakeholder customer); List findAppointmentsByBusinessAndStartTimeBetweenOrEndTimeBetween(Business business, LocalDateTime startTime, LocalDateTime endTime, LocalDateTime startTime1, LocalDateTime endTime1); @Query(value = "select a from Appointment a " + "where business_id = :businessId " + "and (" + "(start_time between :startDate and :endDate) " + "or (end_time between :startDate and :endDate) " + "or (:startDate <= start_time and end_time >= :endDate)" + ")", nativeQuery = true) List findBlockingAppointments(Long businessId, LocalDateTime startDate, LocalDateTime endDate); }