[950fa0d] | 1 | package edu.gjoko.schedlr.repositories;
|
---|
| 2 |
|
---|
| 3 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
| 4 | import edu.gjoko.schedlr.entity.Stakeholder;
|
---|
| 5 | import org.springframework.data.jpa.repository.JpaRepository;
|
---|
| 6 | import org.springframework.data.jpa.repository.Query;
|
---|
| 7 | import org.springframework.stereotype.Repository;
|
---|
| 8 |
|
---|
| 9 | import java.time.LocalDateTime;
|
---|
| 10 | import java.util.List;
|
---|
[77205be] | 11 | import java.util.Optional;
|
---|
[950fa0d] | 12 |
|
---|
| 13 | @Repository
|
---|
| 14 | public interface AppointmentRepository extends JpaRepository<Appointment, Long> {
|
---|
| 15 |
|
---|
[77205be] | 16 | @Query(value = "select ap from Appointment as ap " +
|
---|
| 17 | "where ap.service.business.id = :businessId " +
|
---|
| 18 | "and ap.appointmentStatus = 'NEW'")
|
---|
| 19 | List<Appointment> getActiveAppointmentsByBusiness(Long businessId);
|
---|
[950fa0d] | 20 |
|
---|
[77205be] | 21 | @Query( value = "select ap from Appointment as ap " +
|
---|
| 22 | "where ap.service.business.id = :businessId " +
|
---|
[950fa0d] | 23 | "and (" +
|
---|
[77205be] | 24 | "(ap.startTime between :startDate and :endDate) " +
|
---|
| 25 | "or (ap.endTime between :startDate and :endDate) " +
|
---|
| 26 | "or (:startDate = ap.startTime and ap.startTime = :endDate)" +
|
---|
| 27 | "or (:startDate > ap.startTime and ap.endTime > :endDate)" +
|
---|
| 28 | ")")
|
---|
[950fa0d] | 29 | List<Appointment> findBlockingAppointments(Long businessId, LocalDateTime startDate, LocalDateTime endDate);
|
---|
[77205be] | 30 |
|
---|
| 31 | @Query(value = "select ap from Appointment as ap " +
|
---|
| 32 | "where ap.service.business.owner.id = :businessOwnerId " +
|
---|
| 33 | "and ap.startTime > :now ")
|
---|
| 34 | List<Appointment> findFutureAppointmentsByBusinessOwnerId(Long businessOwnerId, LocalDateTime now);
|
---|
| 35 |
|
---|
| 36 | @Query(value = "select ap from Appointment as ap " +
|
---|
| 37 | "where ap.customer.id = :customerId " +
|
---|
| 38 | "and ap.startTime < :now")
|
---|
| 39 | List<Appointment> findPastAppointmentsByCustomerId(Long customerId, LocalDateTime now);
|
---|
| 40 |
|
---|
| 41 | @Query(value = "select ap from Appointment as ap " +
|
---|
| 42 | "where ap.service.business.owner.id = :businessOwnerId " +
|
---|
| 43 | "and ap.startTime < :now ")
|
---|
| 44 | List<Appointment> findPastAppointmentsByBusinessOwnerId(Long businessOwnerId, LocalDateTime now);
|
---|
| 45 |
|
---|
| 46 | @Query(value = "select ap from Appointment as ap " +
|
---|
| 47 | "where ap.customer.id = :customerId " +
|
---|
| 48 | "and ap.startTime > :now ")
|
---|
| 49 | List<Appointment> findFutureAppointmentsByCustomerId(Long customerId, LocalDateTime now);
|
---|
| 50 |
|
---|
| 51 | Optional<Appointment> findAppointmentByIdAndCustomer_Id(Long id, Long customerId);
|
---|
| 52 |
|
---|
| 53 | Optional<Appointment> findAppointmentByIdAndService_Business_Owner_Id(Long id, Long ownerId);
|
---|
[950fa0d] | 54 | }
|
---|