| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.pollex.pam.domain.Customer; |
| | | import com.pollex.pam.domain.OtpTmp; |
| | |
| | | import com.pollex.pam.service.mapper.CustomerDTOMapper; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class CustomerService { |
| | | |
| | | @Autowired |
| | |
| | | return customerRepository.save(customer); |
| | | } |
| | | |
| | | public String registerCustomer(CustomerRegisterDTO registDTO) { |
| | | public Customer registerCustomer(CustomerRegisterDTO registDTO) { |
| | | boolean isCustomerExist = checkCustomerExist(registDTO); |
| | | if(isCustomerExist) { |
| | | throw new UsernameAlreadyUsedException(); |
| | |
| | | if(otpTmp.getStatus() == OtpTmpStatusEnum.VERRIFIED) { |
| | | Customer customer = customerDTOMapper.toCustomer(registDTO); |
| | | save(customer); |
| | | String jwt = customerAuthService.authorize(account, registDTO.getIndexKey(), registDTO.getOtpCode()); |
| | | return jwt; |
| | | return customer; |
| | | }else { |
| | | throw new UsernameNotFoundException("Otp record not found"); |
| | | throw new IllegalArgumentException("Invalid indexKey state error. IndexKey: " |
| | | + registDTO.getIndexKey() |
| | | + " => status: " + otpTmp.getStatus()); |
| | | } |
| | | } |
| | | |