From 720d89b122e38dea217f8b7bc8dce2698e1d094d Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Mon, 18 Nov 2024 20:21:25 +0900 Subject: [PATCH] =?UTF-8?q?=20feat:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#329)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/auth/AuthorizationInterceptor.java | 3 ++- .../user/application/service/UserService.java | 5 +++++ .../com/listywave/user/application/vo/Nickname.java | 10 ++++++---- .../listywave/user/presentation/UserController.java | 6 ++++++ src/main/resources/application.yml | 6 ++---- 5 files changed, 21 insertions(+), 9 deletions(-) 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(); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0a89fb32..1bff2b7a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,7 @@ spring: datasource: - url: jdbc:mysql://localhost:3306/listywave - username: root - password: root - driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:h2:mem:testdb + username: sa jpa: hibernate: