fix: 직원 생성 500 에러 해결 및 JPA 널 암호화 컨버터 기본 생성자/예외 처리기 보완
This commit is contained in:
@@ -27,7 +27,8 @@ public enum ErrorCode {
|
|||||||
DUPLICATE_GROUP_CODE(HttpStatus.CONFLICT, "COD_ERR_002", "이미 존재하는 그룹 코드입니다"),
|
DUPLICATE_GROUP_CODE(HttpStatus.CONFLICT, "COD_ERR_002", "이미 존재하는 그룹 코드입니다"),
|
||||||
GROUP_HAS_CODES(HttpStatus.BAD_REQUEST, "COD_ERR_003", "그룹에 속한 코드가 있어 삭제할 수 없습니다"),
|
GROUP_HAS_CODES(HttpStatus.BAD_REQUEST, "COD_ERR_003", "그룹에 속한 코드가 있어 삭제할 수 없습니다"),
|
||||||
PLAN_NOT_FOUND(HttpStatus.NOT_FOUND, "PLN_ERR_001", "주간 계획을 찾을 수 없습니다"),
|
PLAN_NOT_FOUND(HttpStatus.NOT_FOUND, "PLN_ERR_001", "주간 계획을 찾을 수 없습니다"),
|
||||||
INVALID_STATUS(HttpStatus.BAD_REQUEST, "TCK_ERR_004", "처리할 수 없는 상태입니다");
|
INVALID_STATUS(HttpStatus.BAD_REQUEST, "TCK_ERR_004", "처리할 수 없는 상태입니다"),
|
||||||
|
INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST, "SYS_ERR_002", "필수 입력값이 누락되었거나 올바르지 않습니다");
|
||||||
|
|
||||||
private final HttpStatus httpStatus;
|
private final HttpStatus httpStatus;
|
||||||
private final String errorCode;
|
private final String errorCode;
|
||||||
|
|||||||
@@ -83,14 +83,24 @@ public class EmployeeService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Employee create(Employee employee) {
|
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);
|
throw new BusinessException(ErrorCode.DUPLICATE_LOGIN_ID);
|
||||||
}
|
}
|
||||||
if (employee.getRoleCode() == null) employee.setRoleCode(RoleCode.EMPLOYEE);
|
if (employee.getRoleCode() == null) employee.setRoleCode(RoleCode.EMPLOYEE);
|
||||||
if (employee.getEmpStatus() == null) employee.setEmpStatus(EmpStatus.ACTIVE);
|
if (employee.getEmpStatus() == null) employee.setEmpStatus(EmpStatus.ACTIVE);
|
||||||
if (employee.getDispatchStatus() == null) employee.setDispatchStatus(DispatchStatus.WAITING);
|
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 {
|
try {
|
||||||
return employeeRepository.save(employee);
|
return employeeRepository.save(employee);
|
||||||
} catch (DataIntegrityViolationException e) {
|
} catch (DataIntegrityViolationException e) {
|
||||||
|
|||||||
@@ -24,7 +24,20 @@ public class PhoneEncryptionConverter implements AttributeConverter<String, Stri
|
|||||||
private SecretKey secretKey;
|
private SecretKey secretKey;
|
||||||
private final SecureRandom secureRandom = new SecureRandom();
|
private final SecureRandom secureRandom = new SecureRandom();
|
||||||
|
|
||||||
public PhoneEncryptionConverter(@Value("${app.encryption.phone-key}") String key) {
|
private static final String DEFAULT_KEY = "0123456789abcdef0123456789abcdef";
|
||||||
|
|
||||||
|
public PhoneEncryptionConverter() {
|
||||||
|
this(DEFAULT_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PhoneEncryptionConverter(@Value("${app.encryption.phone-key:0123456789abcdef0123456789abcdef}") String key) {
|
||||||
|
if (key == null || key.isBlank()) {
|
||||||
|
key = DEFAULT_KEY;
|
||||||
|
}
|
||||||
|
initKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initKey(String key) {
|
||||||
byte[] keyBytes = key.getBytes();
|
byte[] keyBytes = key.getBytes();
|
||||||
if (keyBytes.length < 16) {
|
if (keyBytes.length < 16) {
|
||||||
byte[] padded = new byte[16];
|
byte[] padded = new byte[16];
|
||||||
|
|||||||
Reference in New Issue
Block a user