Skip to content

Commit

Permalink
[refactor] Validation 상수 값 추출
Browse files Browse the repository at this point in the history
- Validate 시 에서 필요한 값을 Validator 의 field 로 추출
  • Loading branch information
kimhyun5u committed Aug 13, 2024
1 parent 7a44fac commit b28cc5d
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import camp.woowak.lab.payaccount.domain.PayAccount;

public class CustomerValidator {
private static final int MAX_NAME_LENGTH = 50;
private static final int MAX_EMAIL_LENGTH = 100;
private static final int MIN_PASSWORD_LENGTH = 8;
private static final int MAX_PASSWORD_LENGTH = 30;
private static final int MAX_PHONE_LENGTH = 30;

private CustomerValidator() {
}
Expand All @@ -22,7 +27,7 @@ public static void validateName(String name) throws InvalidCreationException {
if (name == null || name.isBlank()) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer name cannot be blank");
}
if (name.length() > 50) {
if (name.length() > MAX_NAME_LENGTH) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION,
"Customer name cannot be longer than 50 characters");
}
Expand All @@ -32,7 +37,7 @@ public static void validateEmail(String email) throws InvalidCreationException {
if (email == null || email.isBlank()) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer email cannot be blank");
}
if (email.trim().length() > 100) {
if (email.trim().length() > MAX_EMAIL_LENGTH) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION,
"Customer email cannot be longer than 100 characters");
}
Expand All @@ -42,7 +47,11 @@ public static void validatePassword(String password) throws InvalidCreationExcep
if (password == null || password.isBlank()) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer password cannot be blank");
}
if (password.trim().length() > 30) {
if (password.trim().length() < MIN_PASSWORD_LENGTH) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION,
"Customer password cannot be shorter than 8 characters");
}
if (password.trim().length() > MAX_PASSWORD_LENGTH) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION,
"Customer password cannot be longer than 30 characters");
}
Expand All @@ -52,7 +61,7 @@ public static void validatePhone(String phone) throws InvalidCreationException {
if (phone == null || phone.isBlank()) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer phone cannot be blank");
}
if (phone.trim().length() > 30) {
if (phone.trim().length() > MAX_PHONE_LENGTH) {
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION,
"Customer phone cannot be longer than 30 characters");
}
Expand Down

0 comments on commit b28cc5d

Please sign in to comment.