Ignore:
Timestamp:
01/03/24 00:00:07 (10 months ago)
Author:
gjoko kostadinov <gjokokostadinov@…>
Branches:
master
Children:
53765dd
Parents:
77205be
Message:

Add all bug fixes.

File:
1 edited

Legend:

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

    r77205be r1413ee2  
    44import edu.gjoko.schedlr.entity.StakeholderType;
    55import edu.gjoko.schedlr.repositories.StakeholderRepository;
     6import lombok.RequiredArgsConstructor;
    67import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    78import org.springframework.stereotype.Service;
    89
    9 import java.util.Optional;
    10 
    1110@Service
     11@RequiredArgsConstructor
    1212public class StakeholderService {
    1313
    14     private StakeholderRepository stakeholderRepository;
    15     private BCryptPasswordEncoder bCryptPasswordEncoder;
     14    private final StakeholderRepository stakeholderRepository;
     15    private final BCryptPasswordEncoder bCryptPasswordEncoder;
    1616
    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) {
    2418        stakeholder.setPassword(bCryptPasswordEncoder.encode(stakeholder.getPassword()));
    2519        stakeholder.setStakeholderType(StakeholderType.CUSTOMER);
    26         return stakeholderRepository.save(stakeholder);
     20        stakeholderRepository.save(stakeholder);
    2721    }
    2822
     
    3125    }
    3226
    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);
    4335    }
    4436}
Note: See TracChangeset for help on using the changeset viewer.