Ignore:
Timestamp:
12/26/23 18:50:43 (10 months ago)
Author:
gjoko kostadinov <gjokokostadinov@…>
Branches:
master
Children:
1413ee2
Parents:
950fa0d
Message:

Add entire code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/services/BusinessService.java

    • Property mode changed from 100644 to 100755
    r950fa0d r77205be  
    22
    33import 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;
     4import edu.gjoko.schedlr.repositories.*;
    85import lombok.AllArgsConstructor;
    96import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    107import org.springframework.stereotype.Service;
     8import org.springframework.util.CollectionUtils;
    119
    1210import java.util.List;
     
    2220    private final ServiceTypeRepository serviceTypeRepository;
    2321    private final ServiceRepository serviceRepository;
     22    private final StakeholderService stakeholderService;
    2423
    2524    private final StakeholderRepository stakeholderRepository;
     
    5453                .stream()
    5554                .forEach(business -> {
    56                     stakeholderRepository.save(business.getOwner());
    57                     serviceRepository.saveAll(business.getServices());
    58                     businessRepository.save(business);
     55                    stakeholderService.saveOrUpdateStakeholder(business.getOwner());
     56                    saveOrUpdateServices(business.getServices());
     57                    saveOrUpdateBusiness(business);
    5958                });
    6059    }
     
    6665    }
    6766
    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        }
    7091    }
    7192}
Note: See TracChangeset for help on using the changeset viewer.