|
|
|
@@ -107,19 +107,14 @@ public class AppointmentService {
|
|
|
|
Assert.notNull(from, "from must be not null");
|
|
|
|
Assert.notNull(from, "from must be not null");
|
|
|
|
Assert.notNull(till, "till must be not null");
|
|
|
|
Assert.notNull(till, "till must be not null");
|
|
|
|
|
|
|
|
|
|
|
|
Optional<Garage> garage = garageService.getGarage(garageId);
|
|
|
|
Garage garage = garageService.getGarage(garageId)
|
|
|
|
if (garage.isEmpty())
|
|
|
|
.orElseThrow(() -> new IllegalArgumentException("GarageId not valid"));
|
|
|
|
throw new IllegalArgumentException("GarageId not valid");
|
|
|
|
GarageServices garageService = garage.garageServices().stream()
|
|
|
|
|
|
|
|
.filter(gs -> serviceId == gs.serviceId().getId()).findFirst()
|
|
|
|
|
|
|
|
.orElseThrow(() -> new IllegalArgumentException("serviceId not valid"));
|
|
|
|
|
|
|
|
|
|
|
|
Optional<GarageServices> garageService = garage.get().garageServices().stream()
|
|
|
|
return getValidAppointmentTimeList(garage, garageService, from, till).stream().map(t -> new Appointment()
|
|
|
|
.filter(gs -> serviceId == gs.serviceId().getId()).findFirst();
|
|
|
|
.serviceId(AggregateReference.to(serviceId)).appointmentTime(DateTimeUtil.toDate(t))).toList();
|
|
|
|
if (garageService.isEmpty())
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("serviceId not valid");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getValidAppointmentTimeList(garage.get(), garageService.get(), from, till).stream()
|
|
|
|
|
|
|
|
.map(t -> new Appointment().serviceId(AggregateReference.to(serviceId))
|
|
|
|
|
|
|
|
.appointmentTime(DateTimeUtil.toDate(t)))
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@@ -141,19 +136,17 @@ public class AppointmentService {
|
|
|
|
Assert.notNull(from, "from must be not null");
|
|
|
|
Assert.notNull(from, "from must be not null");
|
|
|
|
Assert.notNull(till, "till must be not null");
|
|
|
|
Assert.notNull(till, "till must be not null");
|
|
|
|
|
|
|
|
|
|
|
|
Optional<Garage> garage = garageService.getGarage(garageId);
|
|
|
|
Garage garage = garageService.getGarage(garageId)
|
|
|
|
if (garage.isEmpty())
|
|
|
|
.orElseThrow(() -> new IllegalArgumentException("GarageId not valid"));
|
|
|
|
throw new IllegalArgumentException("GarageId not valid");
|
|
|
|
MDService service = serviceService.getMDService(serviceId)
|
|
|
|
|
|
|
|
.filter(s -> garage.garageServices().stream().anyMatch(gs -> s.id() == gs.serviceId().getId()))
|
|
|
|
Optional<MDService> service = serviceService.getMDService(serviceId)
|
|
|
|
.orElseThrow(() -> new IllegalArgumentException("serviceId not valid"));
|
|
|
|
.filter(s -> garage.get().garageServices().stream().anyMatch(gs -> s.id() == gs.serviceId().getId()));
|
|
|
|
GarageServices garageServices = garage.garageServices().stream()
|
|
|
|
Optional<GarageServices> garageServices = garage.get().garageServices().stream()
|
|
|
|
.filter(gs -> serviceId == gs.serviceId().getId()).findFirst()
|
|
|
|
.filter(gs -> serviceId == gs.serviceId().getId()).findFirst();
|
|
|
|
.orElseThrow(() -> new IllegalArgumentException("serviceId not valid"));
|
|
|
|
if (service.isEmpty() || garageServices.isEmpty())
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("serviceId not valid");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check appointment times
|
|
|
|
// check appointment times
|
|
|
|
LocalDateTime validAppointmentTime = getValidAppointmentTime(garage.get(), garageServices.get(), from, till);
|
|
|
|
LocalDateTime validAppointmentTime = getValidAppointmentTime(garage, garageServices, from, till);
|
|
|
|
|
|
|
|
|
|
|
|
// create appointment
|
|
|
|
// create appointment
|
|
|
|
if (validAppointmentTime != null) {
|
|
|
|
if (validAppointmentTime != null) {
|
|
|
|
@@ -206,13 +199,13 @@ public class AppointmentService {
|
|
|
|
return appointments < garage.maxAppointments();
|
|
|
|
return appointments < garage.maxAppointments();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Appointment createAppointmentObj(Optional<Garage> garage, Optional<MDService> service,
|
|
|
|
private Appointment createAppointmentObj(Garage garage, MDService service, GarageServices garageService,
|
|
|
|
Optional<GarageServices> garageService, LocalDateTime validAppointmentTime) {
|
|
|
|
LocalDateTime validAppointmentTime) {
|
|
|
|
|
|
|
|
|
|
|
|
Appointment appointment = new Appointment().garageId(AggregateReference.to(garage.get().id()))
|
|
|
|
Appointment appointment = new Appointment().garageId(AggregateReference.to(garage.id()))
|
|
|
|
.appointmentTime(DateTimeUtil.toDate(validAppointmentTime))
|
|
|
|
.appointmentTime(DateTimeUtil.toDate(validAppointmentTime))
|
|
|
|
.serviceId(AggregateReference.to(service.get().id())).serviceCode(service.get().code())
|
|
|
|
.serviceId(AggregateReference.to(service.id())).serviceCode(service.code()).serviceName(service.name())
|
|
|
|
.serviceName(service.get().name()).duration(garageService.get().duration());
|
|
|
|
.duration(garageService.duration());
|
|
|
|
return appointment;
|
|
|
|
return appointment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|