From 0aafdfdb6dddd83fdca6ea2fa542e4a248ed95e5 Mon Sep 17 00:00:00 2001 From: mungsil Date: Sun, 10 Nov 2024 18:11:28 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20ENUM=20=EC=A0=95=EC=9D=98=20#56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/user/service/UserNicknameService.java | 12 +++++------- .../api/global/common/dto/response/Status.java | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/munecting/api/domain/user/service/UserNicknameService.java b/src/main/java/com/munecting/api/domain/user/service/UserNicknameService.java index 3832c3d..9c0467d 100644 --- a/src/main/java/com/munecting/api/domain/user/service/UserNicknameService.java +++ b/src/main/java/com/munecting/api/domain/user/service/UserNicknameService.java @@ -2,7 +2,6 @@ import com.munecting.api.domain.user.dao.UserRepository; import com.munecting.api.domain.user.entity.User; -import com.munecting.api.global.common.dto.response.Status; import com.munecting.api.global.error.exception.InternalServerException; import com.munecting.api.global.error.exception.InvalidValueException; import lombok.RequiredArgsConstructor; @@ -12,6 +11,8 @@ import java.util.Random; +import static com.munecting.api.global.common.dto.response.Status.*; + @Service @Slf4j @RequiredArgsConstructor @@ -23,9 +24,6 @@ public class UserNicknameService { private static final int MAX_LENGTH = 15; private static final String NAME_VALUE_RULES = "^(?=.*[a-zA-Z0-9가-힣])[a-zA-Z가-힣][a-zA-Z0-9가-힣_]*$"; - private static final String NICKNAME_LENGTH_ERROR_MESSAGE = "닉네임은 2-15자 사이여야 합니다."; - private static final String NICKNAME_WRONG_VALUE_ERROR_MESSAGE = "닉네임은 한글, 영문, 숫자, 언더바(_)만 사용 가능하며, 첫 글자는 언더바 또는 숫자일 수 없습니다."; - private static final String NICKNAME_DUPLICATED_ERROR_MESSAGE = "이미 사용 중인 닉네임입니다."; private static final String DEFAULT_NICKNAME = "뮤넥터"; private static final String DELIMITER = "_"; @@ -45,15 +43,15 @@ public String updateNickname(User user, String nickname) { private void validateNickname(User existingUser, String nickname) { if (isInvalidNicknameLength(nickname)) { - throw new InvalidValueException(Status.BAD_REQUEST, NICKNAME_LENGTH_ERROR_MESSAGE); + throw new InvalidValueException(INVALID_NICKNAME_LENGTH); } if (isInvalidNamingRule(nickname)) { - throw new InvalidValueException(Status.BAD_REQUEST, NICKNAME_WRONG_VALUE_ERROR_MESSAGE); + throw new InvalidValueException(INVALID_NICKNAME_VALUE); } if (isDuplicatedNickname(existingUser, nickname)) { - throw new InvalidValueException(Status.CONFLICT, NICKNAME_DUPLICATED_ERROR_MESSAGE); + throw new InvalidValueException(DUPLICATED_NICKNAME); } } diff --git a/src/main/java/com/munecting/api/global/common/dto/response/Status.java b/src/main/java/com/munecting/api/global/common/dto/response/Status.java index dee66d7..47fdace 100644 --- a/src/main/java/com/munecting/api/global/common/dto/response/Status.java +++ b/src/main/java/com/munecting/api/global/common/dto/response/Status.java @@ -44,6 +44,9 @@ public enum Status { // User 오류 응답 USER_NOT_FOUND(HttpStatus.NOT_FOUND, "USER404", "존재하지 않는 회원입니다."), + INVALID_NICKNAME_LENGTH(HttpStatus.BAD_REQUEST, "USER_NICKNAME400", "닉네임은 2-15자 사이여야 합니다."), + INVALID_NICKNAME_VALUE(HttpStatus.BAD_REQUEST, "USER_NICKNAME400", "닉네임은 한글, 영문, 숫자, 언더바(_)만 사용 가능하며, 첫 글자는 언더바 또는 숫자일 수 없습니다."), + DUPLICATED_NICKNAME(HttpStatus.CONFLICT, "USER_NICKNAME409","이미 사용 중인 닉네임입니다."), // 분산락 오류 응답 DISTRIBUTED_LOCK_ACQUISITION_FAILURE(HttpStatus.CONFLICT, "LOCK409", "잠시 후에 시도해주세요."),