diff --git a/src/main/java/leets/weeth/domain/user/service/UserService.java b/src/main/java/leets/weeth/domain/user/service/UserService.java index 36336857..6f82a1c1 100644 --- a/src/main/java/leets/weeth/domain/user/service/UserService.java +++ b/src/main/java/leets/weeth/domain/user/service/UserService.java @@ -5,6 +5,8 @@ import leets.weeth.domain.user.entity.User; import leets.weeth.domain.user.mapper.UserMapper; import leets.weeth.domain.user.repository.UserRepository; +import leets.weeth.global.common.error.exception.custom.StudentIdExistsException; +import leets.weeth.global.common.error.exception.custom.TelExistsException; import leets.weeth.global.common.error.exception.custom.UserExistsException; import leets.weeth.global.common.error.exception.custom.UserNotFoundException; import lombok.RequiredArgsConstructor; @@ -124,10 +126,11 @@ public void validate(String email){ } private void validate(UserDTO.SignUp requestDto) { - if(userRepository.existsByEmail(requestDto.email()) || // 이메일 중복 - userRepository.existsByStudentId(requestDto.studentId()) || // 학번 중복 - userRepository.existsByTel(requestDto.tel())) // 전화번호 중복 - throw new UserExistsException(); + if(userRepository.existsByStudentId(requestDto.studentId())){ + throw new StudentIdExistsException(); + } else if(userRepository.existsByTel(requestDto.tel())){ + throw new TelExistsException(); + } } private void validate(Long userId, UserDTO.Update dto) { diff --git a/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java b/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java index 09b11417..9db17b62 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java +++ b/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java @@ -27,7 +27,9 @@ public enum ExceptionType { NOTICE_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, NoticeTypeNotMatchException.class), ACCOUNT_NOT_FOUND(HttpStatus.BAD_REQUEST, AccountNotFoundException.class), ACCOUNT_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, AccountExistsException.class), - ATTENDANCE_EVENT_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, AttendanceEventTypeNotMatchException.class); + ATTENDANCE_EVENT_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, AttendanceEventTypeNotMatchException.class), + STUDENT_ID_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, StudentIdExistsException.class), + TEL_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, TelExistsException.class); private final HttpStatus httpStatus; private final Class type; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/StudentIdExistsException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/StudentIdExistsException.java new file mode 100644 index 00000000..2a968e91 --- /dev/null +++ b/src/main/java/leets/weeth/global/common/error/exception/custom/StudentIdExistsException.java @@ -0,0 +1,7 @@ +package leets.weeth.global.common.error.exception.custom; + +import jakarta.persistence.EntityNotFoundException; + +public class StudentIdExistsException extends EntityNotFoundException { + public StudentIdExistsException() {super("이미 가입된 학번입니다.");} +} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/TelExistsException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/TelExistsException.java new file mode 100644 index 00000000..c95a0d6b --- /dev/null +++ b/src/main/java/leets/weeth/global/common/error/exception/custom/TelExistsException.java @@ -0,0 +1,7 @@ +package leets.weeth.global.common.error.exception.custom; + +import jakarta.persistence.EntityNotFoundException; + +public class TelExistsException extends EntityNotFoundException { + public TelExistsException() {super("이미 가입된 전화번호 입니다.");} +}