diff --git a/src/main/java/com/listywave/common/auth/AuthorizationInterceptor.java b/src/main/java/com/listywave/common/auth/AuthorizationInterceptor.java index d2d4153e..43a79d91 100644 --- a/src/main/java/com/listywave/common/auth/AuthorizationInterceptor.java +++ b/src/main/java/com/listywave/common/auth/AuthorizationInterceptor.java @@ -37,7 +37,8 @@ public class AuthorizationInterceptor implements HandlerInterceptor { new UriAndMethod("/categories", GET), new UriAndMethod("/users/basic-profile-image", GET), new UriAndMethod("/users/basic-background-image", GET), - new UriAndMethod("/topics", GET) + new UriAndMethod("/topics", GET), + new UriAndMethod("/users/nickname-validate", GET) }; private final JwtManager jwtManager; diff --git a/src/main/java/com/listywave/user/application/service/UserService.java b/src/main/java/com/listywave/user/application/service/UserService.java index e6e92535..47950fb0 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -17,6 +17,7 @@ import com.listywave.user.application.dto.search.UserElasticSearchResponse; import com.listywave.user.application.dto.search.UserSearchResponse; import com.listywave.user.application.dto.search.UserSearchResult; +import com.listywave.user.application.vo.Nickname; import com.listywave.user.repository.follow.FollowRepository; import com.listywave.user.repository.user.UserRepository; import com.listywave.user.repository.user.elastic.UserElasticRepository; @@ -190,4 +191,8 @@ public UserElasticSearchResponse searchUserByElastic(@Nullable Long loginUserId, public User getById(Long userId) { return userRepository.getById(userId); } + + public void validateNickname(String nickname) { + Nickname.of(nickname); + } } diff --git a/src/main/java/com/listywave/user/application/vo/Nickname.java b/src/main/java/com/listywave/user/application/vo/Nickname.java index b485b755..c8fd4956 100644 --- a/src/main/java/com/listywave/user/application/vo/Nickname.java +++ b/src/main/java/com/listywave/user/application/vo/Nickname.java @@ -9,6 +9,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import java.util.Locale; +import java.util.Optional; import java.util.Set; import lombok.AccessLevel; import lombok.EqualsAndHashCode; @@ -69,10 +70,11 @@ private static void validateWord(String value) { private static void validateRelatedWithAdmin(String value) { value = value.toLowerCase(Locale.ENGLISH); - for (String word : BLACK_LIST) { - if (value.contains(word)) { - throw new CustomException(ILLEGAL_NICKNAME_EXCEPTION); - } + Optional result = BLACK_LIST.stream() + .filter(value::contains) + .findAny(); + if (result.isPresent()) { + throw new CustomException(ILLEGAL_NICKNAME_EXCEPTION); } } } diff --git a/src/main/java/com/listywave/user/presentation/UserController.java b/src/main/java/com/listywave/user/presentation/UserController.java index 54b9be2d..08ebb086 100644 --- a/src/main/java/com/listywave/user/presentation/UserController.java +++ b/src/main/java/com/listywave/user/presentation/UserController.java @@ -130,4 +130,10 @@ ResponseEntity searchUserByElastic( UserElasticSearchResponse response = userService.searchUserByElastic(loginUserId, keyword, pageable); return ResponseEntity.ok(response); } + + @GetMapping("/users/nickname-validate") + ResponseEntity validateNickname(@RequestParam(value = "nickname") String nickname) { + userService.validateNickname(nickname); + return ResponseEntity.ok().build(); + } }