Changeset 950fa0d for src/main/java/edu/gjoko/schedlr/services
- Timestamp:
- 05/24/23 23:18:47 (18 months ago)
- Branches:
- master
- Children:
- 77205be
- Parents:
- 8bcd64c
- Location:
- src/main/java/edu/gjoko/schedlr/services
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/services/BusinessService.java
r8bcd64c r950fa0d 1 1 package edu.gjoko.schedlr.services; 2 2 3 import edu.gjoko.schedlr.entity.Business; 4 import edu.gjoko.schedlr.entity.ServiceType; 5 import edu.gjoko.schedlr.entity.Stakeholder; 6 import edu.gjoko.schedlr.entity.StakeholderType; 3 import edu.gjoko.schedlr.entity.*; 7 4 import edu.gjoko.schedlr.repositories.BusinessRepository; 5 import edu.gjoko.schedlr.repositories.ServiceRepository; 8 6 import edu.gjoko.schedlr.repositories.ServiceTypeRepository; 7 import edu.gjoko.schedlr.repositories.StakeholderRepository; 9 8 import lombok.AllArgsConstructor; 10 9 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; … … 13 12 import java.util.List; 14 13 14 import static edu.gjoko.schedlr.entity.BusinessStatus.ACTIVE; 15 15 import static edu.gjoko.schedlr.entity.BusinessStatus.NEW; 16 16 … … 21 21 private final BusinessRepository businessRepository; 22 22 private final ServiceTypeRepository serviceTypeRepository; 23 private final ServiceRepository serviceRepository; 24 25 private final StakeholderRepository stakeholderRepository; 23 26 private BCryptPasswordEncoder bCryptPasswordEncoder; 24 27 … … 51 54 .stream() 52 55 .forEach(business -> { 56 stakeholderRepository.save(business.getOwner()); 57 serviceRepository.saveAll(business.getServices()); 53 58 businessRepository.save(business); 54 59 }); … … 60 65 return businessRepository.findBusinessByOwner(owner); 61 66 } 67 68 public List<Business> findByBusinessTypeAndActiveStatus(BusinessType businessType) { 69 return businessRepository.findBusinessesByBusinessTypeAndBusinessStatus(businessType, ACTIVE); 70 } 62 71 } -
src/main/java/edu/gjoko/schedlr/services/PostgresUserDetailsService.java
r8bcd64c r950fa0d 8 8 import edu.gjoko.schedlr.repositories.StakeholderRepository; 9 9 import lombok.RequiredArgsConstructor; 10 import org.springframework.security.access.AccessDeniedException;11 10 import org.springframework.security.core.GrantedAuthority; 12 11 import org.springframework.security.core.authority.SimpleGrantedAuthority; … … 15 14 import org.springframework.security.core.userdetails.UserDetailsService; 16 15 import org.springframework.security.core.userdetails.UsernameNotFoundException; 17 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;18 16 import org.springframework.stereotype.Service; 19 17 … … 26 24 27 25 private final StakeholderRepository stakeholderRepository; 28 private final BCryptPasswordEncoder bCryptPasswordEncoder;29 30 26 private final BusinessRepository businessRepository; 31 27 … … 33 29 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 34 30 Stakeholder user = stakeholderRepository.findStakeholderByUsername(username); 35 if (user == null) {31 if (user == null) { 36 32 throw new UsernameNotFoundException("Non existing user"); 37 33 } 38 34 39 if (user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) {35 if (user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) { 40 36 Business business = businessRepository.findBusinessByOwner(user); 41 37 if (business.getBusinessStatus() != BusinessStatus.ACTIVE) { -
src/main/java/edu/gjoko/schedlr/services/StakeholderService.java
r8bcd64c r950fa0d 24 24 return stakeholderRepository.save(stakeholder); 25 25 } 26 27 public Stakeholder findById(Long id) { 28 return stakeholderRepository.findById(id).get(); 29 } 26 30 }
Note:
See TracChangeset
for help on using the changeset viewer.