保誠-保戶業務員媒合平台
Mila
2021-11-29 98891d1d1bcaa414f336b9c05ad94d39fe9cb1bc
pamapi/src/main/java/com/pollex/pam/service/CustomerService.java
@@ -2,6 +2,9 @@
import java.util.Optional;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.dto.CustomerDTO;
import com.pollex.pam.service.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@@ -31,6 +34,9 @@
   @Autowired
   OtpTmpService otpTmpService;
   
    @Autowired
    CustomerMapper customerMapper;
   public Customer save(Customer customer) {
      return customerRepository.save(customer);
   }
@@ -57,6 +63,25 @@
      
   }
    public void updateLoggedCustomer(CustomerDTO customerDTO) {
        Long customerId = SecurityUtils.getCustomerDBId();
        Customer customer = customerRepository.findById(customerId)
            .orElseThrow(() -> new UsernameNotFoundException("customerId which is from token is not found in customer db table, customer id = " + customerId));
        customer.setEmail(customerDTO.getEmail());
        customer.setPhone(customerDTO.getPhone());
        customer.setName(customerDTO.getName());
        customerRepository.save(customer);
    }
    public CustomerDTO getLoggedCustomerDTO() {
        Long customerId = SecurityUtils.getCustomerDBId();
        Customer customer = customerRepository.findById(customerId)
            .orElseThrow(() -> new UsernameNotFoundException("customerId which is from token is not found in customer db table, customer id = " + customerId));
        return customerMapper.toDto(customer);
    }
   private String getCustomerAccount(CustomerRegisterDTO registDTO) {
      return registDTO.getContactType() == OtpLoginTypeEnum.EMAIL?registDTO.getEmail():registDTO.getPhone();
   }