Skip to content

Commit

Permalink
feat: 닉네임 유효성 검증 API 구현 (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Nov 18, 2024
1 parent 4c5c154 commit 720d89b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
10 changes: 6 additions & 4 deletions src/main/java/com/listywave/user/application/vo/Nickname.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> result = BLACK_LIST.stream()
.filter(value::contains)
.findAny();
if (result.isPresent()) {
throw new CustomException(ILLEGAL_NICKNAME_EXCEPTION);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,10 @@ ResponseEntity<UserElasticSearchResponse> searchUserByElastic(
UserElasticSearchResponse response = userService.searchUserByElastic(loginUserId, keyword, pageable);
return ResponseEntity.ok(response);
}

@GetMapping("/users/nickname-validate")
ResponseEntity<Void> validateNickname(@RequestParam(value = "nickname") String nickname) {
userService.validateNickname(nickname);
return ResponseEntity.ok().build();
}
}
6 changes: 2 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 720d89b

Please sign in to comment.