1 | package edu.gjoko.schedlr.services;
|
---|
2 |
|
---|
3 | import edu.gjoko.schedlr.entity.Stakeholder;
|
---|
4 | import edu.gjoko.schedlr.entity.StakeholderType;
|
---|
5 | import edu.gjoko.schedlr.repositories.StakeholderRepository;
|
---|
6 | import lombok.RequiredArgsConstructor;
|
---|
7 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | @Service
|
---|
11 | @RequiredArgsConstructor
|
---|
12 | public 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 | }
|
---|