source: src/main/java/edu/gjoko/schedlr/services/StakeholderService.java

Last change on this file was 1413ee2, checked in by gjoko kostadinov <gjokokostadinov@…>, 11 months ago

Add all bug fixes.

  • Property mode set to 100755
File size: 1.4 KB
Line 
1package edu.gjoko.schedlr.services;
2
3import edu.gjoko.schedlr.entity.Stakeholder;
4import edu.gjoko.schedlr.entity.StakeholderType;
5import edu.gjoko.schedlr.repositories.StakeholderRepository;
6import lombok.RequiredArgsConstructor;
7import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
8import org.springframework.stereotype.Service;
9
10@Service
11@RequiredArgsConstructor
12public class StakeholderService {
13
14 private final StakeholderRepository stakeholderRepository;
15 private final BCryptPasswordEncoder bCryptPasswordEncoder;
16
17 public void saveStakeholder(Stakeholder stakeholder) {
18 stakeholder.setPassword(bCryptPasswordEncoder.encode(stakeholder.getPassword()));
19 stakeholder.setStakeholderType(StakeholderType.CUSTOMER);
20 stakeholderRepository.save(stakeholder);
21 }
22
23 public Stakeholder findById(Long id) {
24 return stakeholderRepository.findById(id).get();
25 }
26
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);
35 }
36}
Note: See TracBrowser for help on using the repository browser.