Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.util.List;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.MEMBER_NOT_EXISTS_WITH_STUDENT_ID;
import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Service
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.*;
import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Service
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import jakarta.validation.constraints.Pattern;

import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.STUDENT_ID_REGEX;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.EMAIL_INVALID_FORMAT;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.STUDENT_ID_INVALID_FORMAT;

public record PasswordUpdateLinkSendRequest(
@Pattern(regexp = STUDENT_ID_REGEX, message = STUDENT_ID_INVALID_FORMAT)
@Pattern(regexp = STUDENT_ID_REGEX, message = "학번 형식이 올바르지 않습니다.")
String studentId,
@Email(message = EMAIL_INVALID_FORMAT)
@Email(message = "이메일 형식이 올바르지 않습니다.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request 에서 검증 메서드의 상수화가 사라지는 부분이 아쉬운 것 같은데, 에러 메세지에 대한 상수와 에러 코드 포맷을 같이 가져가서, 에러 코드 포맷 내에서 상수 메세지를 같이 활용하는 건 어떻게 생각하시나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STUDENT_ID_INVALID_FORMAT(null, "", "학번 형식이 올바르지 않습니다.");

제가 이해한게 맞다면 ErrorCode에 요런 형식의 값을 추가해서 메시지 필드를 활용하는거 맞을까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아아 기존 에러메시지 상수 클래스를 그대로 운영하면서 에러 코드 포맷에서 에러메시지 상수를 사용하는 방법인건가요???

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 말을 어렵게 적었었네요.. 에러메세지 상수 클래스와 에러 코드 포맷 같이 유지하는 방식 맞습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋을 것 같습니다!! 저도 저 부분 아쉬웠어서 에러메시지 클래스 다시 살려보겠습니다~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEMBER_NOT_EXISTS_WITH_STUDENT_ID(NOT_FOUND, "MEMBER-001", ErrorMessage.MEMBER_NOT_EXISTS_WITH_STUDENT_ID),
DUPLICATED_STUDENT_ID(CONFLICT, "MEMBER-002", ErrorMessage.DUPLICATED_STUDENT_ID),
DUPLICATED_EMAIL(CONFLICT, "MEMBER-003", ErrorMessage.DUPLICATED_EMAIL),
PASSWORD_IS_DIFFERENT_FROM_CHECK(BAD_REQUEST, "MEMBER-004", ErrorMessage.PASSWORD_IS_DIFFERENT_FROM_CHECK),

에러 코드 포맷 내의 메세지까지 상수 메세지를 활용하려니까 오히려 ErrorCode 클래스를 봤을 때 정보성이 떨어지는 것 같습니다...ㅠㅠ
Pattern에 들어가는 메세지만 상수화 시키고 에러 코드 포맷의 메세지는 문자열을 사용하는 건 어떨까요?

Copy link
Member

@kckc0608 kckc0608 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 ErrorMessage. 부분을 제거해도 (정적 임포트) 비슷하게 보일까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEMBER_NOT_EXISTS_WITH_STUDENT_ID(NOT_FOUND, "MEMBER-001", MEMBER_NOT_EXISTS_WITH_STUDENT_ID),
DUPLICATED_STUDENT_ID(CONFLICT, "MEMBER-002", DUPLICATED_STUDENT_ID),
DUPLICATED_EMAIL(CONFLICT, "MEMBER-003", DUPLICATED_EMAIL),
PASSWORD_IS_DIFFERENT_FROM_CHECK(BAD_REQUEST, "MEMBER-004", PASSWORD_IS_DIFFERENT_FROM_CHECK),

이런식으로 나오는데 이전에 있었던 상황처럼
프론트 측에서 백엔드에 잘못된 api 반환으로 "~"의 에러메세지가 온다 라고 확인 요청이 들어왔을 때
에러코드를 보면서 메세지를 확인하려면 에러메세지 클래스와 왔다갔다 하면서 확인해야 하는게 정보성이 떨어진다고 생각했습니다..!
+) 그리고 지금 에러코드와 연관된 에러메세지의 이름이 같아서 정적 임포트를 사용하려면 한쪽의 이름을 다 바꾸어야 하는 상황입니다ㅠ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 그렇군요ㅠㅠ
그러면 말씀하신 방향대로 에러코드 포맷에서는 그냥 문자열을 사용하는 걸로 가죠 👍

String email
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import jakarta.validation.constraints.Pattern;

import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.PASSWORD_REGEX;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.PASSWORD_INVALID_FORMAT;

public record PasswordUpdateRequest(
@NotNull(message = "비밀번호 변경을 위한 토큰값은 필수입니다.")
String token,
@Pattern(regexp = PASSWORD_REGEX, message = PASSWORD_INVALID_FORMAT)
@Pattern(regexp = PASSWORD_REGEX, message = "비밀번호는 특수문자, 영문자, 숫자를 포함한 8자리 이상 문자열입니다.")
String newPassword
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.PASSWORD_REGEX;
import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.STUDENT_ID_REGEX;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.PASSWORD_INVALID_FORMAT;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
Expand All @@ -19,7 +18,7 @@ public record LoginRequest(
@NotBlank(message = "비밀번호를 입력해주세요.")
@Pattern(
regexp = PASSWORD_REGEX,
message = PASSWORD_INVALID_FORMAT
message = "비밀번호는 특수문자, 영문자, 숫자를 포함한 8자리 이상 문자열입니다."
)
String password
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;
import static com.keunsori.keunsoriserver.global.constant.UrlConstant.PASSWORD_CHANGE_LINK;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.STUDENT_ID_NOT_EXISTS;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.*;

@Service
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.keunsori.keunsoriserver.domain.email.domain;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.EMAIL_VERIFY_FAILED;

import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;

Expand All @@ -11,6 +9,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Getter
@RedisHash(value = "emailAuthentication", timeToLive = 300)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.keunsori.keunsoriserver.domain.email.service;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.EMAIL_NOT_EXISTS_FOR_AUTH;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.EMAIL_VERIFY_NUMBER_GENERATION_FAILED;

import org.springframework.stereotype.Service;

import com.keunsori.keunsoriserver.domain.email.domain.EmailAuthentication;
Expand All @@ -16,6 +13,8 @@
import java.security.SecureRandom;
import lombok.RequiredArgsConstructor;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Service
@RequiredArgsConstructor
public class EmailService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

import java.time.LocalDateTime;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.INVALID_STATUS_FOR_APPROVAL;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.STUDENT_ID_DOES_NOT_MATCH_WITH_EMAIL;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Entity
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import jakarta.validation.constraints.Pattern;

import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.PASSWORD_REGEX;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.PASSWORD_INVALID_FORMAT;

public record MemberPasswordUpdateRequest(
@NotBlank(message = "기존 비밀번호를 입력해주세요.")
String currentPassword,
@NotBlank(message = "새 비밀번호를 입력해주세요.")
@Pattern(regexp = PASSWORD_REGEX, message = PASSWORD_INVALID_FORMAT)
@Pattern(regexp = PASSWORD_REGEX, message = "비밀번호는 특수문자, 영문자, 숫자를 포함한 8자리 이상 문자열입니다.")
String newPassword
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.PASSWORD_REGEX;
import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.STUDENT_ID_REGEX;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.PASSWORD_INVALID_FORMAT;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
Expand All @@ -23,7 +22,7 @@ public record SignUpRequest(
String email,

@NotBlank(message = "비밀번호는 필수 입력값입니다.")
@Pattern(regexp = PASSWORD_REGEX, message = PASSWORD_INVALID_FORMAT)
@Pattern(regexp = PASSWORD_REGEX, message = "비밀번호는 특수문자, 영문자, 숫자를 포함한 8자리 이상 문자열입니다.")
String password,

@NotBlank(message = "비밀번호를 한 번 더 입력해주세요.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.keunsori.keunsoriserver.global.constant.RequestFormatConstant.PASSWORD_REGEX;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.*;
import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Service
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.keunsori.keunsoriserver.domain.member.service;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.DUPLICATED_EMAIL;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.DUPLICATED_STUDENT_ID;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.PASSWORD_IS_DIFFERENT_FROM_CHECK;

import com.keunsori.keunsoriserver.domain.member.domain.Member;
import com.keunsori.keunsoriserver.domain.member.repository.MemberRepository;
Expand All @@ -15,6 +12,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Service
@RequiredArgsConstructor
public class SignUpService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.keunsori.keunsoriserver.domain.reservation.domain.validator;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.ANOTHER_RESERVATION_ALREADY_EXISTS;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.INVALID_RESERVATION_DATE;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.INVALID_RESERVATION_TIME;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.RESERVATION_ALREADY_COMPLETED;
import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.RESERVATION_NOT_EQUAL_MEMBER;

import org.springframework.stereotype.Component;

import com.keunsori.keunsoriserver.domain.member.domain.Member;
Expand All @@ -21,6 +15,8 @@
import java.time.LocalTime;
import lombok.RequiredArgsConstructor;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Component
@RequiredArgsConstructor
public class ReservationValidator {
Expand Down Expand Up @@ -119,4 +115,4 @@ private void validateReservationDateIsNotPast(LocalDate reservationDate) {
throw new ReservationException(INVALID_RESERVATION_DATE);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.keunsori.keunsoriserver.domain.reservation.domain.vo;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.INVALID_RESERVATION_TYPE;

import com.keunsori.keunsoriserver.global.exception.ReservationException;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

public enum ReservationType {
TEAM, PERSONAL, LESSON;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.keunsori.keunsoriserver.domain.reservation.domain.vo;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.INVALID_SESSION;

import com.keunsori.keunsoriserver.global.exception.ReservationException;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

public enum Session {
VOCAL, KEYBOARD, DRUM, GUITAR, BASS, ALL;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.keunsori.keunsoriserver.domain.reservation.service;

import static com.keunsori.keunsoriserver.global.exception.ErrorMessage.RESERVATION_NOT_EXISTS_WITH_ID;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -23,6 +21,8 @@

import lombok.RequiredArgsConstructor;

import static com.keunsori.keunsoriserver.global.exception.ErrorCode.*;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.keunsori.keunsoriserver.global.exception;

public class AuthException extends RuntimeException {
import lombok.Getter;

public AuthException(String message) {
super(message);
@Getter
public class AuthException extends RuntimeException {
private ErrorCode errorCode;
public AuthException(ErrorCode errorCode) {
super(errorCode.getMassage());
this.errorCode = errorCode;
}


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.keunsori.keunsoriserver.global.exception;

public class EmailException extends RuntimeException {
import lombok.Getter;

public EmailException(String message) {
super(message);
@Getter
public class EmailException extends RuntimeException {
private ErrorCode errorCode;
public EmailException(ErrorCode errorCode) {
super(errorCode.getMassage());
this.errorCode = errorCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.keunsori.keunsoriserver.global.exception;

import lombok.Getter;

@Getter
public enum ErrorCode {
INVALID_INPUT_VALUE(400, "COMMON-001", "유효성 검증에 실패했습니다."),
INTERNAL_SERVER_ERROR(500,"COMMON-002", "서버에서 처리할 수 없습니다."),
Comment on lines +7 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INTERNAL_ERROR(INTERNAL_SERVER_ERROR, "내부 서버 에러가 발생했습니다. 관리자에게 문의 바랍니다."),
METHOD_ARGUMENT_NULL(BAD_REQUEST, "인자는 null이 될 수 없습니다."),
METHOD_ARGUMENT_NOT_VALID(BAD_REQUEST, "인자가 유효하지 않습니다."),
REGEX_VIOLATION(BAD_REQUEST, "정규표현식을 위반했습니다."),
FORBIDDEN_ACCESS(FORBIDDEN, "접근 권한이 없습니다."),

상태코드 숫자를 이렇게 상수로 적으면 가독성이 더 좋을 것 같은데 어떻게 생각하시나요?
(위 코드에서 상수는 이미 정의된 org.springframework.http.HttpStatus.*; 패키지 상수를 가져다가 사용한 케이스입니다)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은거 같습니다! 그럼 숫자는 상수로 적고 "COMMON-001" <- 이 도메인 코드는 그대로 남기면 되겟죠??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다!


// Member
MEMBER_NOT_EXISTS_WITH_STUDENT_ID(404, "MEMBER-001", "해당 학번을 가진 멤버가 존재하지 않습니다."),
DUPLICATED_STUDENT_ID(409, "MEMBER-002", "이미 존재하는 학번입니다."),
DUPLICATED_EMAIL(409, "MEMBER-003", "이미 존재하는 이메일입니다."),
PASSWORD_IS_DIFFERENT_FROM_CHECK(400, "MEMBER-004", "비밀번호와 비밀번호 확인 입력값이 다릅니다."),
PASSWORD_INVALID_FORMAT(400, "MEMBER-005", "비밀번호는 특수문자, 영문자, 숫자를 포함한 8자리 이상 문자열입니다."),
INVALID_CURRENT_PASSWORD(400, "MEMBER-006", "현재 비밀번호가 올바르지 않습니다."),
PASSWORD_SAME_AS_OLD(400, "MEMBER-007", "새 비밀번호가 기존 비밀번호와 동일합니다."),
STUDENT_ID_DOES_NOT_MATCH_WITH_EMAIL(400, "MEMBER-008", "가입한 학번과 이메일이 일치하지 않습니다"),

// Admin Member
INVALID_STATUS_FOR_APPROVAL(400, "ADMIN-MEMBER-001", "회원이 승인 대기 상태가 아닙니다."),

// Reservation
RESERVATION_NOT_EXISTS_WITH_ID(404, "RESERVATION-001", "해당 아이디 값을 가진 예약이 존재하지 않습니다."),
RESERVATION_NOT_EQUAL_MEMBER(403, "RESERVATION-002", "예약한 멤버가 아닙니다."),
RESERVATION_ALREADY_COMPLETED(400, "RESERVATION-003", "확정된 예약은 수정/취소할 수 없습니다."),
ANOTHER_RESERVATION_ALREADY_EXISTS(409, "RESERVATION-004", "해당 시간대에 다른 예약이 존재합니다."),
INVALID_RESERVATION_TIME(400, "RESERVATION-005", "예약 종료 시간은 예약 시작 시간보다 나중이어야 합니다."),
INVALID_RESERVATION_TYPE(400, "RESERVATION-006", "예약 타입이 잘못되었습니다."),
INVALID_RESERVATION_DATE(400, "RESERVATION-007", "예약 날짜는 과거 날짜면 안됩니다."),
INVALID_SESSION(404, "RESERVATION-008", "존재하지 않는 세션입니다."),

// Admin Reservation
INVALID_DATE_SCHEDULE(400, "ADMIN-RESERVATION-001", "설정하는 날짜가 이미 지난 날짜입니다."),
INVALID_SCHEDULE_TIME(400, "ADMIN-RESERVATION-002", "시작 시간과 끝 시간의 순서가 올바르지 않습니다."),

// Auth
STUDENT_ID_NOT_EXISTS(404, "AUTH-001", "존재하지 않는 학번입니다."),
INVALID_PASSWORD(401, "AUTH-002", "비밀번호가 일치하지 않습니다.") ,
INVALID_REFRESH_TOKEN(401, "AUTH-003", "유효하지 않은 리프레시 토큰입니다."),
INVALID_TOKEN(401, "AUTH-004", "유효하지 않은 토큰입니다."),
EXPIRED_TOKEN(401, "AUTH-005", "만료된 토큰입니다."),

// Email
EMAIL_NOT_EXISTS_FOR_AUTH(400, "EMAIL-001", "인증번호를 전송하지 않았거나 인증번호가 만료되었습니다."),
EMAIL_VERIFY_FAILED(400, "EMAIL-002", "인증번호가 일치하지 않습니다."),
EMAIL_VERIFY_NUMBER_GENERATION_FAILED(500, "EMAIL-003", "인증번호 생성중 에러가 발생했습니다.");


private final int status;
private final String code;
private final String massage;

ErrorCode(int status, String code, String massage) {
this.status = status;
this.code = code;
this.massage = massage;
}
}

This file was deleted.

Loading
Loading