Ignore:
Timestamp:
05/24/23 23:18:47 (18 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
77205be
Parents:
8bcd64c
Message:

Periodic update

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  
    11package edu.gjoko.schedlr.services;
    22
    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;
     3import edu.gjoko.schedlr.entity.*;
    74import edu.gjoko.schedlr.repositories.BusinessRepository;
     5import edu.gjoko.schedlr.repositories.ServiceRepository;
    86import edu.gjoko.schedlr.repositories.ServiceTypeRepository;
     7import edu.gjoko.schedlr.repositories.StakeholderRepository;
    98import lombok.AllArgsConstructor;
    109import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
     
    1312import java.util.List;
    1413
     14import static edu.gjoko.schedlr.entity.BusinessStatus.ACTIVE;
    1515import static edu.gjoko.schedlr.entity.BusinessStatus.NEW;
    1616
     
    2121    private final BusinessRepository businessRepository;
    2222    private final ServiceTypeRepository serviceTypeRepository;
     23    private final ServiceRepository serviceRepository;
     24
     25    private final StakeholderRepository stakeholderRepository;
    2326    private BCryptPasswordEncoder bCryptPasswordEncoder;
    2427
     
    5154                .stream()
    5255                .forEach(business -> {
     56                    stakeholderRepository.save(business.getOwner());
     57                    serviceRepository.saveAll(business.getServices());
    5358                    businessRepository.save(business);
    5459                });
     
    6065        return businessRepository.findBusinessByOwner(owner);
    6166    }
     67
     68    public List<Business> findByBusinessTypeAndActiveStatus(BusinessType businessType) {
     69        return businessRepository.findBusinessesByBusinessTypeAndBusinessStatus(businessType, ACTIVE);
     70    }
    6271}
  • src/main/java/edu/gjoko/schedlr/services/PostgresUserDetailsService.java

    r8bcd64c r950fa0d  
    88import edu.gjoko.schedlr.repositories.StakeholderRepository;
    99import lombok.RequiredArgsConstructor;
    10 import org.springframework.security.access.AccessDeniedException;
    1110import org.springframework.security.core.GrantedAuthority;
    1211import org.springframework.security.core.authority.SimpleGrantedAuthority;
     
    1514import org.springframework.security.core.userdetails.UserDetailsService;
    1615import org.springframework.security.core.userdetails.UsernameNotFoundException;
    17 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    1816import org.springframework.stereotype.Service;
    1917
     
    2624
    2725    private final StakeholderRepository stakeholderRepository;
    28     private final BCryptPasswordEncoder bCryptPasswordEncoder;
    29 
    3026    private final BusinessRepository businessRepository;
    3127
     
    3329    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    3430        Stakeholder user = stakeholderRepository.findStakeholderByUsername(username);
    35         if(user == null) {
     31        if (user == null) {
    3632            throw new UsernameNotFoundException("Non existing user");
    3733        }
    3834
    39         if(user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) {
     35        if (user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) {
    4036            Business business = businessRepository.findBusinessByOwner(user);
    4137            if (business.getBusinessStatus() != BusinessStatus.ACTIVE) {
  • src/main/java/edu/gjoko/schedlr/services/StakeholderService.java

    r8bcd64c r950fa0d  
    2424        return stakeholderRepository.save(stakeholder);
    2525    }
     26
     27    public Stakeholder findById(Long id) {
     28        return stakeholderRepository.findById(id).get();
     29    }
    2630}
Note: See TracChangeset for help on using the changeset viewer.