fix: 직원 생성 500 에러 해결 및 JPA 널 암호화 컨버터 기본 생성자/예외 처리기 보완
This commit is contained in:
@@ -83,14 +83,24 @@ public class EmployeeService {
|
||||
|
||||
@Transactional
|
||||
public Employee create(Employee employee) {
|
||||
if (employee.getEmail() != null && employeeRepository.findByEmail(employee.getEmail()).isPresent()) {
|
||||
if (employee.getLoginId() == null || employee.getLoginId().isBlank()) {
|
||||
throw new BusinessException(ErrorCode.INVALID_INPUT_VALUE);
|
||||
}
|
||||
if (employeeRepository.findByLoginId(employee.getLoginId()).isPresent()) {
|
||||
throw new BusinessException(ErrorCode.DUPLICATE_LOGIN_ID);
|
||||
}
|
||||
if (employee.getEmail() != null && !employee.getEmail().isBlank() && employeeRepository.findByEmail(employee.getEmail()).isPresent()) {
|
||||
throw new BusinessException(ErrorCode.DUPLICATE_LOGIN_ID);
|
||||
}
|
||||
if (employee.getRoleCode() == null) employee.setRoleCode(RoleCode.EMPLOYEE);
|
||||
if (employee.getEmpStatus() == null) employee.setEmpStatus(EmpStatus.ACTIVE);
|
||||
if (employee.getDispatchStatus() == null) employee.setDispatchStatus(DispatchStatus.WAITING);
|
||||
|
||||
employee.setPassword(passwordEncoder.encode(employee.getPassword()));
|
||||
String rawPassword = employee.getPassword();
|
||||
if (rawPassword == null || rawPassword.isBlank()) {
|
||||
rawPassword = "admin123";
|
||||
}
|
||||
employee.setPassword(passwordEncoder.encode(rawPassword));
|
||||
try {
|
||||
return employeeRepository.save(employee);
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
|
||||
Reference in New Issue
Block a user