[950fa0d] | 1 | package edu.gjoko.schedlr.services;
|
---|
| 2 |
|
---|
| 3 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
| 4 | import edu.gjoko.schedlr.entity.Business;
|
---|
| 5 | import edu.gjoko.schedlr.entity.Stakeholder;
|
---|
| 6 | import edu.gjoko.schedlr.exceptions.BlockingTimeException;
|
---|
| 7 | import edu.gjoko.schedlr.repositories.AppointmentRepository;
|
---|
| 8 | import edu.gjoko.schedlr.repositories.ServiceRepository;
|
---|
| 9 | import edu.gjoko.schedlr.repositories.ServiceTypeRepository;
|
---|
| 10 | import lombok.AllArgsConstructor;
|
---|
| 11 | import org.springframework.stereotype.Service;
|
---|
| 12 |
|
---|
| 13 | import java.util.List;
|
---|
| 14 |
|
---|
| 15 | @Service
|
---|
| 16 | @AllArgsConstructor
|
---|
| 17 | public class AppointmentsService {
|
---|
| 18 |
|
---|
| 19 | private final AppointmentRepository appointmentRepository;
|
---|
| 20 |
|
---|
| 21 | private final ServiceRepository serviceRepository;
|
---|
| 22 |
|
---|
| 23 | public void saveAppointment(Appointment appointment) {
|
---|
| 24 | var service = serviceRepository.findById(appointment.getService().getId()).get();
|
---|
| 25 | appointment.setEndTime(appointment.getStartTime().plusMinutes(service.getDuration()));
|
---|
| 26 | List<Appointment> blockingAppointments = appointmentRepository.
|
---|
| 27 | findBlockingAppointments(
|
---|
| 28 | appointment.getBusiness().getId(), appointment.getStartTime(), appointment.getEndTime());
|
---|
| 29 |
|
---|
| 30 | // check to see if there are blocking exceptions
|
---|
| 31 | if (blockingAppointments != null && !blockingAppointments.isEmpty()) {
|
---|
| 32 | throw new BlockingTimeException();
|
---|
| 33 | }
|
---|
| 34 | appointmentRepository.save(appointment);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public List<Appointment> getAppointmentsByBusiness(Business business) {
|
---|
| 38 | return appointmentRepository.getAppointmentsByBusiness(business);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | private List<Appointment> getAppointmentsByCustomer(Stakeholder stakeholder) {
|
---|
| 42 | return appointmentRepository.getAppointmentsByCustomer(stakeholder);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|