Changeset 77205be for src/main/java/edu
- Timestamp:
- 12/26/23 18:50:43 (11 months ago)
- Branches:
- master
- Children:
- 1413ee2
- Parents:
- 950fa0d
- Location:
- src/main/java/edu/gjoko/schedlr
- Files:
-
- 17 added
- 2 deleted
- 31 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/SchedlrApplication.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/ServletInitializer.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/config/AppAuthenticationEntryPoint.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/config/AppAuthenticationFailureHandler.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/config/AppConfig.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 15 15 } 16 16 17 @Bean18 public AuthenticationSuccessHandler appAuthenticationSuccessHandler() {19 return new AppAuthenticationSuccessHandler();20 }21 17 22 18 @Bean -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/config/AppFilter.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 64 64 break; 65 65 case "CUSTOMER": 66 page = "/homepage"; 66 if ("/customer_admin".equals(httpServletRequest.getRequestURI())) { 67 page = "/customer_admin"; 68 } else { 69 page = "/homepage"; 70 } 67 71 break; 68 72 case "BUSINESS_OWNER": -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 32 32 private final BCryptPasswordEncoder passwordEncoder; 33 33 34 private final AuthenticationSuccessHandler authenticationSuccessHandler;35 36 34 private final AuthenticationFailureHandler authenticationFailureHandler; 37 35 … … 57 55 .loginPage("/login") 58 56 .loginProcessingUrl("/login") 59 .successHandler(authenticationSuccessHandler)60 57 .failureHandler(authenticationFailureHandler) 61 .defaultSuccessUrl("/ homepage")58 .defaultSuccessUrl("/login") 62 59 .and() 63 60 .logout(logout -> logout -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/config/MvcConfig.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 16 16 registry.addViewController("/admin").setViewName("admin"); 17 17 registry.addViewController("/business_admin").setViewName("business_admin"); 18 registry.addViewController("/customer_admin").setViewName("customer_admin"); 18 19 } 19 20 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/AdministrationController.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 8 8 9 9 import javax.servlet.http.HttpServletRequest; 10 import java.security.Principal;11 10 12 11 @Controller 13 public class Admin Controller {12 public class AdministrationController { 14 13 15 14 @GetMapping(path = "/admin") 16 public String getAdminPageTemplate(Model model , HttpServletRequest request) {15 public String getAdminPageTemplate(Model model) { 17 16 return "admin"; 18 17 } 19 18 20 19 @GetMapping(path = "/business_admin") 21 public String getBusinessAdminPageTemplate(Model model , HttpServletRequest request) {22 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();23 String currentPrincipalName = authentication.getName();20 public String getBusinessAdminPageTemplate(Model model) { 21 return "business_admin"; 22 } 24 23 25 return "business_admin"; 24 @GetMapping(path = "/customer_admin") 25 public String getCustomerAdminPageTemplate(Model model) { 26 return "customer_admin"; 26 27 } 27 28 -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/HomePageController.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/LoginController.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/RegisterController.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/rest/BusinessApi.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 2 2 3 3 import edu.gjoko.schedlr.entity.Business; 4 import edu.gjoko.schedlr.entity.BusinessType;5 4 import edu.gjoko.schedlr.services.BusinessService; 6 5 import lombok.AllArgsConstructor; … … 13 12 @RequestMapping("api/business") 14 13 @AllArgsConstructor 15 public class Business Controller{14 public class BusinessApi { 16 15 17 final BusinessService businessService;16 private final BusinessService businessService; 18 17 19 18 @PostMapping 20 public void getBusinessTypes(@RequestBody Business business) {19 public void saveBusiness(@RequestBody Business business) { 21 20 businessService.saveBusiness(business); 22 21 } … … 40 39 @GetMapping(path = "/{businessTypeId}") 41 40 public List<Business> getBusinessesByBusinessType(@PathVariable("businessTypeId") Long id) { 42 BusinessType businessType = new BusinessType(); 43 businessType.setId(id); 44 return businessService.findByBusinessTypeAndActiveStatus(businessType); 41 return businessService.findByBusinessTypeAndActiveStatus(id); 45 42 } 46 43 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/rest/NomenclatureApi.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 13 13 @RequestMapping("api/nomenclatures") 14 14 @AllArgsConstructor 15 public class Nomenclature Controller{15 public class NomenclatureApi { 16 16 17 17 private final NomenclaturesService nomenclaturesService; -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/controllers/rest/UserApi.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 1 1 package edu.gjoko.schedlr.controllers.rest; 2 2 3 import edu.gjoko.schedlr.entity.Business;4 3 import lombok.AllArgsConstructor; 5 4 import org.springframework.web.bind.annotation.GetMapping; … … 8 7 9 8 import javax.servlet.http.HttpServletRequest; 10 import java.util.List;11 9 12 10 @RestController 13 11 @RequestMapping("api/user") 14 12 @AllArgsConstructor 15 public class User Controller{13 public class UserApi { 16 14 17 15 @GetMapping(path = "/me") -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/Appointment.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 1 1 package edu.gjoko.schedlr.entity; 2 2 3 import lombok.AllArgsConstructor; 4 import lombok.Getter; 5 import lombok.NoArgsConstructor; 6 import lombok.Setter; 3 import com.fasterxml.jackson.annotation.JsonBackReference; 4 import lombok.*; 7 5 import org.springframework.data.annotation.LastModifiedDate; 8 6 import org.springframework.data.jpa.domain.support.AuditingEntityListener; … … 14 12 @EntityListeners(AuditingEntityListener.class) 15 13 @Table(name = "appointment") 16 @Getter 17 @Setter 14 @Data 18 15 @NoArgsConstructor 19 16 @AllArgsConstructor … … 30 27 private LocalDateTime endTime; 31 28 32 @OneToOne 33 @JoinColumn(name = "customer_id", referencedColumnName = "id") 29 @ManyToOne 30 @JoinColumn(name = "stakeholder_id") 31 @JsonBackReference(value = "customerAppointments") 34 32 private Stakeholder customer; 35 33 36 34 @ManyToOne 37 @JoinColumn(name = "business_id") 38 private Business business; 35 @JoinColumn(name = "service_id") 36 @JsonBackReference(value = "serviceAppointments") 37 private Service service; 39 38 40 @ ManyToOne41 @ JoinColumn(name = "service_id")42 private Service service;39 @Column(name = "appointment_status", length = 32, columnDefinition = "varchar(32) default 'NEW'") 40 @Enumerated(EnumType.STRING) 41 private AppointmentStatus appointmentStatus = AppointmentStatus.NEW; 43 42 44 43 @Column(name = "created") … … 49 48 @LastModifiedDate 50 49 private LocalDateTime modified; 50 51 public String getTimePeriod() { 52 return startTime + " - " + endTime; 53 } 54 51 55 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/Business.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 37 37 private BusinessType businessType; 38 38 39 @ ManyToOne()39 @OneToOne(cascade = CascadeType.PERSIST) 40 40 @JoinColumn(name = "owner_id", referencedColumnName = "id", nullable = false) 41 41 @JsonProperty("owner") … … 43 43 44 44 @OneToMany(mappedBy = "business", cascade = CascadeType.PERSIST) 45 @JsonManagedReference 45 @JsonManagedReference(value = "services") 46 46 private List<Service> services; 47 47 -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/BusinessStatus.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/BusinessType.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/Service.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 3 3 import com.fasterxml.jackson.annotation.JsonBackReference; 4 4 import com.fasterxml.jackson.annotation.JsonIgnore; 5 import com.fasterxml.jackson.annotation.JsonManagedReference; 5 6 import lombok.AllArgsConstructor; 6 7 import lombok.Getter; … … 13 14 import javax.persistence.*; 14 15 import java.time.LocalDateTime; 16 import java.util.List; 15 17 16 18 @Entity … … 33 35 private Integer price; 34 36 35 @OneToOne(cascade = CascadeType.PERSIST) 37 @Column(name = "cumulated_rating") 38 private Float rating = 0.0f; 39 40 @Column(name = "reviews_count") 41 private Integer reviewsCount = 0; 42 43 @OneToOne(cascade = CascadeType.MERGE) 36 44 @JoinColumn(name = "service_type_id", referencedColumnName = "id") 37 45 private ServiceType serviceType; … … 39 47 @ManyToOne 40 48 @JoinColumn(name = "business_id") 41 @JsonBackReference 49 @JsonBackReference(value = "services") 42 50 private Business business; 51 52 @OneToMany(mappedBy="service") 53 @JsonManagedReference(value = "serviceAppointments") 54 private List<Appointment> appointments; 43 55 44 56 @Column(name = "created") -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/ServiceType.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/Stakeholder.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 2 2 3 3 import com.fasterxml.jackson.annotation.JsonIgnore; 4 import com.fasterxml.jackson.annotation.JsonManagedReference; 4 5 import lombok.AllArgsConstructor; 5 6 import lombok.Getter; … … 12 13 import javax.persistence.*; 13 14 import java.time.LocalDateTime; 15 import java.util.List; 14 16 15 17 @Entity … … 39 41 private String email; 40 42 43 @Column(name = "phone_number") 44 private String phoneNumber; 45 41 46 @Column(name = "username") 42 47 private String username; … … 44 49 @Column(name = "password") 45 50 private String password; 51 52 @OneToMany(mappedBy = "customer") 53 @JsonManagedReference(value = "customerAppointments") 54 private List<Appointment> appointments; 46 55 47 56 @Column(name = "created") … … 54 63 @JsonIgnore 55 64 private LocalDateTime modified; 65 66 public String getFullName() { 67 return firstName + " " + lastName; 68 } 56 69 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/entity/StakeholderType.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/exceptions/BlockingTimeException.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 3 3 public class BlockingTimeException extends RuntimeException { 4 4 5 public static final String MESSAGE = " The selected dates are overlapping with another appointment";5 public static final String MESSAGE = "Error! The selected dates are overlapping with another appointment."; 6 6 public BlockingTimeException() { 7 7 super(MESSAGE); -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/repositories/AppointmentRepository.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 2 2 3 3 import edu.gjoko.schedlr.entity.Appointment; 4 import edu.gjoko.schedlr.entity.Business;5 4 import edu.gjoko.schedlr.entity.Stakeholder; 6 5 import org.springframework.data.jpa.repository.JpaRepository; … … 10 9 import java.time.LocalDateTime; 11 10 import java.util.List; 11 import java.util.Optional; 12 12 13 13 @Repository 14 14 public interface AppointmentRepository extends JpaRepository<Appointment, Long> { 15 15 16 List<Appointment> getAppointmentsByBusiness(Business business); 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); 17 20 18 List<Appointment> getAppointmentsByCustomer(Stakeholder customer); 21 @Query( value = "select ap from Appointment as ap " + 22 "where ap.service.business.id = :businessId " + 23 "and (" + 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 ")") 29 List<Appointment> findBlockingAppointments(Long businessId, LocalDateTime startDate, LocalDateTime endDate); 19 30 20 List<Appointment> findAppointmentsByBusinessAndStartTimeBetweenOrEndTimeBetween(Business business, LocalDateTime startTime, LocalDateTime endTime, LocalDateTime startTime1, LocalDateTime endTime1); 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); 21 35 22 @Query(value = "select a from Appointment a " + 23 "where business_id = :businessId " + 24 "and (" + 25 "(start_time between :startDate and :endDate) " + 26 "or (end_time between :startDate and :endDate) " + 27 "or (:startDate <= start_time and end_time >= :endDate)" + 28 ")", nativeQuery = true) 29 List<Appointment> findBlockingAppointments(Long businessId, LocalDateTime startDate, LocalDateTime endDate); 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); 30 54 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/repositories/BusinessRepository.java
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 17 17 18 18 List<Business> findBusinessesByBusinessTypeAndBusinessStatus(BusinessType businessType, BusinessStatus businessStatus); 19 20 List<Business> findBusinessesByBusinessStatusAndBusinessType_Id(BusinessStatus businessStatus, Long id); 19 21 } -
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/repositories/BusinessTypeRepository.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/repositories/ServiceRepository.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/repositories/ServiceTypeRepository.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
src/main/java/edu/gjoko/schedlr/repositories/StakeholderRepository.java
-
Property mode
changed from
100644
to100755
-
Property mode
changed from
-
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.