Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 닉네임 유효성 검증 API 구현 #330

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading