Skip to content
Merged
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
@@ -1,6 +1,8 @@
package life.mosu.mosuserver.domain.profile.entity;

import java.util.Arrays;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
import life.mosu.mosuserver.global.exception.ErrorCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -18,6 +20,6 @@ public static Gender fromName(String genderName) {
.filter(g -> g.getGenderName().equals(genderName))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException("Invalid gender name: " + genderName));
() -> new CustomRuntimeException(ErrorCode.INVAILD_GENDER));

Choose a reason for hiding this comment

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

high

Following the correction of the typo in ErrorCode from INVAILD_GENDER to INVALID_GENDER, this line should be updated to use the correct enum constant.

Suggested change
() -> new CustomRuntimeException(ErrorCode.INVAILD_GENDER));
() -> new CustomRuntimeException(ErrorCode.INVALID_GENDER));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package life.mosu.mosuserver.global.annotation;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Pattern(
regexp = "^01[016789]-\\d{3,4}-\\d{4}$",
message = "전화번호 형식은 010-XXXX-XXXX 이어야 합니다."
)
@NotBlank
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {})
public @interface NotBlankPhoneNumberPattern {

String message() default "전화번호 형식은 010-XXXX-XXXX 이어야 합니다.";
Comment on lines +12 to +22

Choose a reason for hiding this comment

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

medium

The current error message is specific to pattern violations and might be confusing if the validation fails because the phone number is blank. A more comprehensive message that covers both NotBlank and Pattern violations would be better. Consider updating the message in both the @Pattern annotation and the default message() to inform the user about both requirements.

Suggested change
@Pattern(
regexp = "^01[016789]-\\d{3,4}-\\d{4}$",
message = "전화번호 형식은 010-XXXX-XXXX 이어야 합니다."
)
@NotBlank
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {})
public @interface NotBlankPhoneNumberPattern {
String message() default "전화번호 형식은 010-XXXX-XXXX 이어야 합니다.";
@Pattern(
regexp = "^01[016789]-\\d{3,4}-\\d{4}$",
message = "전화번호는 필수이며, 형식은 010-XXXX-XXXX 이어야 합니다."
)
@NotBlank
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {})
public @interface NotBlankPhoneNumberPattern {
String message() default "전화번호는 필수이며, 형식은 010-XXXX-XXXX 이어야 합니다.";


Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
regexp = "^01[016789]-\\d{3,4}-\\d{4}$",
message = "전화번호 형식은 010-XXXX-XXXX 이어야 합니다."
)

@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum ErrorCode {
USER_INFO_INVALID(HttpStatus.BAD_REQUEST, "유효하지 않은 사용자 정보입니다."),
USER_NOT_ACCESS_FORBIDDEN(HttpStatus.BAD_REQUEST, "접근 권한이 없는 사용자입니다"),
USER_SAVE_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "사용자 저장에 실패했습니다."),
INVAILD_GENDER(HttpStatus.BAD_REQUEST, "유효하지 않은 성별 값입니다."),

Choose a reason for hiding this comment

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

high

There's a typo in the enum constant name. It should be INVALID_GENDER instead of INVAILD_GENDER. This improves code clarity and prevents potential confusion. Please ensure all usages of this enum constant, such as in Gender.java, are updated accordingly.

Suggested change
INVAILD_GENDER(HttpStatus.BAD_REQUEST, "유효하지 않은 성별 값입니다."),
INVALID_GENDER(HttpStatus.BAD_REQUEST, "유효하지 않은 성별 값입니다."),

// 신청 관련 에러
WRONG_SUBJECT_TYPE(HttpStatus.BAD_REQUEST, "잘못된 과목명 입니다."),
WRONG_LUNCH_TYPE(HttpStatus.BAD_REQUEST, "잘못된 도시락명 입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import life.mosu.mosuserver.domain.user.entity.AuthProvider;
import life.mosu.mosuserver.domain.user.entity.UserJpaEntity;
import life.mosu.mosuserver.domain.user.entity.UserRole;
import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
import life.mosu.mosuserver.global.exception.ErrorCode;
import life.mosu.mosuserver.presentation.common.FileRequest;
Expand All @@ -27,7 +27,7 @@ public record ApplicationGuestRequest(
String userName,
@JsonFormat(pattern = "yyyy-MM-dd")
LocalDate birth,
@PhoneNumberPattern
@NotBlankPhoneNumberPattern
String phoneNumber,
@NotNull
ExamApplicationRequest examApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import life.mosu.mosuserver.domain.user.entity.UserJpaEntity;
import life.mosu.mosuserver.domain.user.entity.UserRole;
import life.mosu.mosuserver.global.annotation.LoginIdPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.PasswordPattern;
import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import org.springframework.security.crypto.password.PasswordEncoder;

public record SignUpAccountRequest(
Expand Down Expand Up @@ -45,7 +45,7 @@ public record SignUpAccountRequest(

@Schema(description = "휴대폰 번호", example = "010-1234-5678", required = true)
@NotBlank(message = "휴대폰 번호는 필수입니다.")

Choose a reason for hiding this comment

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

medium

The @NotBlank annotation here is redundant because the @NotBlankPhoneNumberPattern composite annotation already includes @NotBlank. You can remove this line to avoid redundancy and rely on the validation provided by @NotBlankPhoneNumberPattern.

@PhoneNumberPattern
@NotBlankPhoneNumberPattern
String phoneNumber,

SignUpServiceTermRequest serviceTermRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package life.mosu.mosuserver.presentation.profile.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;

public record RecommenderRegistrationRequest(
@Schema(description = "추천인 전화번호 (전화번호 형식은 010-XXXX-XXXX 이어야 합니다.)", example = "010-8765-4322")
@PhoneNumberPattern
@NotBlankPhoneNumberPattern
String phoneNumber
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import life.mosu.mosuserver.domain.profile.entity.Gender;
import life.mosu.mosuserver.domain.profile.entity.Grade;
import life.mosu.mosuserver.domain.profile.entity.ProfileJpaEntity;
import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;

@Schema(description = "프로필 등록 요청 DTO")
public record SignUpProfileRequest(
Expand All @@ -29,7 +29,7 @@ public record SignUpProfileRequest(

@Schema(description = "휴대폰 번호", example = "010-1234-5678", required = true)
@NotBlank(message = "휴대폰 번호는 필수입니다.")

Choose a reason for hiding this comment

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

medium

The @NotBlank annotation here is redundant because the @NotBlankPhoneNumberPattern composite annotation already includes @NotBlank. You can remove this line to avoid redundancy and rely on the validation provided by @NotBlankPhoneNumberPattern.

@PhoneNumberPattern
@NotBlankPhoneNumberPattern
String phoneNumber,

@Schema(description = "이메일 주소", example = "hong@example.com")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import jakarta.validation.constraints.NotBlank;
import life.mosu.mosuserver.domain.recommendation.RecommendationJpaEntity;
import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;

public record RecommendationRequest(
@NotBlank String name,
@PhoneNumberPattern String phoneNumber,
@NotBlankPhoneNumberPattern String phoneNumber,
@NotBlank String bank,
@NotBlank String accountNumber
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package life.mosu.mosuserver.presentation.user.dto.request;

import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;

public record FindLoginIdRequest(
String name,
@PhoneNumberPattern
@NotBlankPhoneNumberPattern
String phoneNumber
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package life.mosu.mosuserver.presentation.user.dto.request;

import life.mosu.mosuserver.global.annotation.LoginIdPattern;
import life.mosu.mosuserver.global.annotation.PhoneNumberPattern;
import life.mosu.mosuserver.global.annotation.NotBlankPhoneNumberPattern;

public record FindPasswordRequest(
String name,
@LoginIdPattern
String loginId,
@PhoneNumberPattern
@NotBlankPhoneNumberPattern
String phoneNumber
) {

Expand Down