Changeset 77205be for src/main/java/edu/gjoko/schedlr/services
- Timestamp:
- 12/26/23 18:50:43 (11 months ago)
- Branches:
- master
- Children:
- 1413ee2
- Parents:
- 950fa0d
- Location:
- src/main/java/edu/gjoko/schedlr/services
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/services/AppointmentsService.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 1 1 package edu.gjoko.schedlr.services; 2 2 3 import edu.gjoko.schedlr.entity.Appointment; 4 import edu.gjoko.schedlr.entity.Business; 5 import edu.gjoko.schedlr.entity.Stakeholder; 3 import edu.gjoko.schedlr.dto.AppointmentInfoDto; 4 import edu.gjoko.schedlr.entity.*; 6 5 import edu.gjoko.schedlr.exceptions.BlockingTimeException; 6 import edu.gjoko.schedlr.mappers.AppointmentInfoDtoBusinessMapper; 7 import edu.gjoko.schedlr.mappers.AppointmentInfoDtoCustomerMapper; 7 8 import edu.gjoko.schedlr.repositories.AppointmentRepository; 8 9 import edu.gjoko.schedlr.repositories.ServiceRepository; 9 import edu.gjoko.schedlr.repositories.S erviceTypeRepository;10 import edu.gjoko.schedlr.repositories.StakeholderRepository; 10 11 import lombok.AllArgsConstructor; 11 12 import org.springframework.stereotype.Service; 12 13 14 import javax.persistence.EntityNotFoundException; 15 import javax.security.sasl.AuthenticationException; 16 import java.time.LocalDateTime; 17 import java.util.ArrayList; 13 18 import java.util.List; 19 import java.util.Optional; 14 20 15 21 @Service … … 18 24 19 25 private final AppointmentRepository appointmentRepository; 26 private final StakeholderRepository stakeholderRepository; 27 private final ServiceRepository serviceRepository; 28 private final AppointmentInfoDtoBusinessMapper appointmentInfoDtoBusinessMapper; 29 private final AppointmentInfoDtoCustomerMapper appointmentInfoDtoCustomerMapper; 20 30 21 private final ServiceRepository serviceRepository;22 31 23 32 public void saveAppointment(Appointment appointment) { 24 33 var service = serviceRepository.findById(appointment.getService().getId()).get(); 25 appointment.setEndTime(appointment.getStartTime().plusMinutes(service.getDuration())); 34 35 // remove 1 minute in order to prevent overlapping 36 appointment.setEndTime(appointment.getStartTime().plusMinutes(service.getDuration() - 1)); 26 37 List<Appointment> blockingAppointments = appointmentRepository. 27 38 findBlockingAppointments( 28 appointment.get Business().getId(), appointment.getStartTime(), appointment.getEndTime());39 appointment.getService().getBusiness().getId(), appointment.getStartTime(), appointment.getEndTime()); 29 40 30 41 // check to see if there are blocking exceptions … … 35 46 } 36 47 37 public List<Appointment> getAppointmentsByBusiness(Business business) { 38 return appointmentRepository.getAppointmentsByBusiness(business); 48 public List<AppointmentInfoDto> getFutureAppointmentInfoList(Long stakeholderId) { 49 StakeholderType type = stakeholderRepository.findById(stakeholderId).get().getStakeholderType(); 50 List<AppointmentInfoDto> appointmentInfoDtoList = new ArrayList<>(); 51 52 switch (type) { 53 case BUSINESS_OWNER -> appointmentInfoDtoList = appointmentRepository.findFutureAppointmentsByBusinessOwnerId(stakeholderId, LocalDateTime.now()) 54 .stream() 55 .map(appointmentInfoDtoBusinessMapper::appointmentToAppointmentInfoDto) 56 .toList(); 57 case CUSTOMER -> appointmentInfoDtoList = appointmentRepository.findFutureAppointmentsByCustomerId(stakeholderId, LocalDateTime.now()) 58 .stream() 59 .map(appointmentInfoDtoCustomerMapper::appointmentToAppointmentInfoDto) 60 .toList(); 61 } 62 63 return appointmentInfoDtoList; 39 64 } 40 65 41 private List<Appointment> getAppointmentsByCustomer(Stakeholder stakeholder) { 42 return appointmentRepository.getAppointmentsByCustomer(stakeholder); 66 public List<AppointmentInfoDto> getPastAppointmentInfoList(Long stakeholderId) { 67 StakeholderType type = stakeholderRepository.findById(stakeholderId).get().getStakeholderType(); 68 List<Appointment> appointmentInfoDtoList = new ArrayList<>(); 69 70 switch (type) { 71 case BUSINESS_OWNER -> appointmentInfoDtoList = appointmentRepository.findPastAppointmentsByBusinessOwnerId(stakeholderId, LocalDateTime.now()); 72 case CUSTOMER -> appointmentInfoDtoList = appointmentRepository.findPastAppointmentsByCustomerId(stakeholderId, LocalDateTime.now()); 73 } 74 75 return appointmentInfoDtoList 76 .stream() 77 .map(appointmentInfoDtoBusinessMapper::appointmentToAppointmentInfoDto) 78 .toList(); 79 80 } 81 82 public List<Appointment> getActiveAppointmentsByBusiness(Long businessId) { 83 return appointmentRepository.getActiveAppointmentsByBusiness(businessId); 84 } 85 86 public void deleteAppointment(Long appointmentId, Long stakeholderId) throws AuthenticationException { 87 Optional<Stakeholder> stakeholderOptional = stakeholderRepository.findById(stakeholderId); 88 if (stakeholderOptional.isPresent()) { 89 Optional<Appointment> optional = appointmentRepository.findAppointmentByIdAndCustomer_Id(appointmentId, stakeholderId); 90 if (optional.isEmpty()) { 91 optional = appointmentRepository.findAppointmentByIdAndService_Business_Owner_Id(appointmentId, stakeholderId); 92 if (optional.isEmpty()) { 93 throw new EntityNotFoundException("No appointment was found for the give stakeholder and appointment id."); 94 } else { 95 softDeleteAppointment(optional.get(), AppointmentStatus.CANCELLED_BY_BUSINESS_OWNER); 96 } 97 } else { 98 softDeleteAppointment(optional.get(), AppointmentStatus.CANCELLED_BY_CUSTOMER); 99 } 100 } else { 101 throw new AuthenticationException(); 102 } 103 } 104 105 public void softDeleteAppointment(Appointment appointment, AppointmentStatus appointmentStatus) { 106 appointment.setAppointmentStatus(appointmentStatus); 107 appointmentRepository.save(appointment); 43 108 } 44 109 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/services/BusinessService.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 2 2 3 3 import edu.gjoko.schedlr.entity.*; 4 import edu.gjoko.schedlr.repositories.BusinessRepository; 5 import edu.gjoko.schedlr.repositories.ServiceRepository; 6 import edu.gjoko.schedlr.repositories.ServiceTypeRepository; 7 import edu.gjoko.schedlr.repositories.StakeholderRepository; 4 import edu.gjoko.schedlr.repositories.*; 8 5 import lombok.AllArgsConstructor; 9 6 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 7 import org.springframework.stereotype.Service; 8 import org.springframework.util.CollectionUtils; 11 9 12 10 import java.util.List; … … 22 20 private final ServiceTypeRepository serviceTypeRepository; 23 21 private final ServiceRepository serviceRepository; 22 private final StakeholderService stakeholderService; 24 23 25 24 private final StakeholderRepository stakeholderRepository; … … 54 53 .stream() 55 54 .forEach(business -> { 56 stakeholder Repository.save(business.getOwner());57 s erviceRepository.saveAll(business.getServices());58 businessRepository.save(business);55 stakeholderService.saveOrUpdateStakeholder(business.getOwner()); 56 saveOrUpdateServices(business.getServices()); 57 saveOrUpdateBusiness(business); 59 58 }); 60 59 } … … 66 65 } 67 66 68 public List<Business> findByBusinessTypeAndActiveStatus(BusinessType businessType) { 69 return businessRepository.findBusinessesByBusinessTypeAndBusinessStatus(businessType, ACTIVE); 67 public List<Business> findByBusinessTypeAndActiveStatus(Long businessTypeId) { 68 return businessRepository.findBusinessesByBusinessStatusAndBusinessType_Id(ACTIVE, businessTypeId); 69 } 70 71 72 73 private void saveOrUpdateBusiness(Business business) { 74 if (business.getId() != null) { 75 var foundBusinessEntity = businessRepository.findById(business.getId()); 76 business.setCreated(foundBusinessEntity.get().getCreated()); 77 } 78 businessRepository.save(business); 79 } 80 81 private void saveOrUpdateServices(List<edu.gjoko.schedlr.entity.Service> serviceList) { 82 if (!CollectionUtils.isEmpty(serviceList)) { 83 serviceList.forEach( service -> { 84 if (service.getId() != null) { 85 var found = serviceRepository.findById(service.getId()); 86 service.setCreated(found.get().getCreated()); 87 } 88 }); 89 serviceRepository.saveAll(serviceList); 90 } 70 91 } 71 92 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/services/NomenclaturesService.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/services/PostgresUserDetailsService.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/services/StakeholderService.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 6 6 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 7 7 import org.springframework.stereotype.Service; 8 9 import java.util.Optional; 8 10 9 11 @Service … … 28 30 return stakeholderRepository.findById(id).get(); 29 31 } 32 33 public void saveOrUpdateStakeholder(Stakeholder stakeholder) { 34 if (stakeholder.getId() != null) { 35 var found = stakeholderRepository.findById(stakeholder.getId()).get(); 36 found.setFirstName(stakeholder.getFirstName()); 37 found.setLastName(stakeholder.getLastName()); 38 found.setPhoneNumber(stakeholder.getPhoneNumber()); 39 found.setEmail(stakeholder.getEmail()); 40 found.setUsername(stakeholder.getUsername()); 41 stakeholderRepository.save(found); 42 } 43 } 30 44 } -
Property mode
changed from
Note:
See TracChangeset
for help on using the changeset viewer.