Skip to content

Commit

Permalink
feat: 닉네임 유효성 검증 API 구현 (#329) (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho authored Nov 18, 2024
1 parent 9bcd25a commit fd39272
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 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();
}
}

0 comments on commit fd39272

Please sign in to comment.