- Timestamp:
- 01/03/24 00:00:07 (10 months ago)
- Branches:
- master
- Children:
- 53765dd
- Parents:
- 77205be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/services/StakeholderService.java
r77205be r1413ee2 4 4 import edu.gjoko.schedlr.entity.StakeholderType; 5 5 import edu.gjoko.schedlr.repositories.StakeholderRepository; 6 import lombok.RequiredArgsConstructor; 6 7 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 7 8 import org.springframework.stereotype.Service; 8 9 9 import java.util.Optional;10 11 10 @Service 11 @RequiredArgsConstructor 12 12 public class StakeholderService { 13 13 14 private StakeholderRepository stakeholderRepository;15 private BCryptPasswordEncoder bCryptPasswordEncoder;14 private final StakeholderRepository stakeholderRepository; 15 private final BCryptPasswordEncoder bCryptPasswordEncoder; 16 16 17 public StakeholderService(StakeholderRepository stakeholderRepository, 18 BCryptPasswordEncoder bCryptPasswordEncoder) { 19 this.stakeholderRepository = stakeholderRepository; 20 this.bCryptPasswordEncoder = bCryptPasswordEncoder; 21 } 22 23 public Stakeholder saveStakeholder(Stakeholder stakeholder) { 17 public void saveStakeholder(Stakeholder stakeholder) { 24 18 stakeholder.setPassword(bCryptPasswordEncoder.encode(stakeholder.getPassword())); 25 19 stakeholder.setStakeholderType(StakeholderType.CUSTOMER); 26 returnstakeholderRepository.save(stakeholder);20 stakeholderRepository.save(stakeholder); 27 21 } 28 22 … … 31 25 } 32 26 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 } 27 public void saveOrUpdateStakeholder(Stakeholder stakeholder, Long businessOwnerId) { 28 var found = stakeholderRepository.findById(businessOwnerId).get(); 29 found.setFirstName(stakeholder.getFirstName()); 30 found.setLastName(stakeholder.getLastName()); 31 found.setPhoneNumber(stakeholder.getPhoneNumber()); 32 found.setEmail(stakeholder.getEmail()); 33 found.setUsername(stakeholder.getUsername()); 34 stakeholderRepository.save(found); 43 35 } 44 36 }
Note:
See TracChangeset
for help on using the changeset viewer.