Conversation
Walkthrough팔로우 기능을 사용자 ID 기반에서 닉네임 기반으로 리팩토링하고, 프로필 업데이트 시 닉네임 중복 검증을 추가하며, 새로운 예외 클래스와 저장소 메서드를 도입하고 관련 API 엔드포인트를 수정했습니다. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20-25 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/main/java/team/wego/wegobackend/common/exception/AppErrorCode.java(1 hunks)src/main/java/team/wego/wegobackend/user/application/FollowService.java(1 hunks)src/main/java/team/wego/wegobackend/user/application/UserService.java(2 hunks)src/main/java/team/wego/wegobackend/user/exception/SameNicknameException.java(1 hunks)src/main/java/team/wego/wegobackend/user/presentation/UserController.java(2 hunks)src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java(1 hunks)src/main/java/team/wego/wegobackend/user/repository/UserRepository.java(1 hunks)src/test/http/user/user-api.http(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/team/wego/wegobackend/user/application/UserService.java (1)
src/main/java/team/wego/wegobackend/user/exception/SameNicknameException.java (1)
SameNicknameException(6-11)
🔇 Additional comments (6)
src/main/java/team/wego/wegobackend/common/exception/AppErrorCode.java (1)
31-31: 새로운 에러 코드 추가가 적절합니다.닉네임 중복 검증을 위한 에러 코드가 올바르게 정의되었습니다.
src/test/http/user/user-api.http (1)
67-67: 테스트 엔드포인트가 올바르게 변경되었습니다.팔로우 API가 닉네임 기반 쿼리 파라미터를 사용하도록 정확히 반영되었습니다.
src/main/java/team/wego/wegobackend/user/exception/SameNicknameException.java (1)
6-11: 예외 클래스가 올바르게 구현되었습니다.
AppException을 확장하고 적절한 에러 코드를 사용하여 닉네임 중복 예외를 정의했습니다.src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java (1)
47-50: API 문서가 올바르게 업데이트되었습니다.팔로우 메서드 시그니처가 닉네임 기반으로 정확히 변경되었습니다.
src/main/java/team/wego/wegobackend/user/presentation/UserController.java (1)
103-114: 팔로우 엔드포인트가 올바르게 변경되었습니다.닉네임 기반 팔로우 로직으로 API가 정확히 수정되었으며, 쿼리 파라미터 바인딩과 서비스 호출이 올바르게 연결되었습니다.
src/main/java/team/wego/wegobackend/user/application/FollowService.java (1)
28-30: 닉네임 기반 자기 팔로우 검증이 올바르게 구현되었습니다.ID 대신 닉네임으로 자기 자신을 팔로우하는 것을 방지하는 로직이 정확합니다.
| public void follow(String followNickname, Long followerId) { | ||
| User follower = userRepository.findById(followerId) | ||
| .orElseThrow(UserNotFoundException::new); | ||
|
|
||
| User follow = userRepository.findById(followId) | ||
| if (followNickname.equals(follower.getNickName())) { | ||
| throw new SameFollowException(); | ||
| } | ||
|
|
||
| User follow = userRepository.findByNickName(followNickname) | ||
| .orElseThrow(UserNotFoundException::new); | ||
|
|
||
| followRepository.save(Follow.builder() | ||
| .follower(follower) | ||
| .follow(follow) | ||
| .build()); | ||
| if (followRepository.existsByFollowerIdAndFolloweeId(followerId, follow.getId())) { | ||
| throw new ExistFollowException(); | ||
| } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
팔로우 관계 저장 로직이 누락되었습니다.
검증 로직만 수행하고 Follow 엔티티를 생성하거나 저장하는 코드가 없어서 팔로우 관계가 데이터베이스에 저장되지 않습니다. 이는 팔로우 기능이 동작하지 않는 치명적인 버그입니다.
다음과 같이 Follow 엔티티를 생성하고 저장하는 로직을 추가해야 합니다:
if (followRepository.existsByFollowerIdAndFolloweeId(followerId, follow.getId())) {
throw new ExistFollowException();
}
+
+ Follow followEntity = Follow.builder()
+ .follower(follower)
+ .followee(follow)
+ .build();
+ followRepository.save(followEntity);
}또한, 파일 상단에 Follow 엔티티 import를 추가해야 합니다:
import team.wego.wegobackend.user.domain.User;
+import team.wego.wegobackend.user.domain.Follow;
import team.wego.wegobackend.user.exception.ExistFollowException;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public void follow(String followNickname, Long followerId) { | |
| User follower = userRepository.findById(followerId) | |
| .orElseThrow(UserNotFoundException::new); | |
| User follow = userRepository.findById(followId) | |
| if (followNickname.equals(follower.getNickName())) { | |
| throw new SameFollowException(); | |
| } | |
| User follow = userRepository.findByNickName(followNickname) | |
| .orElseThrow(UserNotFoundException::new); | |
| followRepository.save(Follow.builder() | |
| .follower(follower) | |
| .follow(follow) | |
| .build()); | |
| if (followRepository.existsByFollowerIdAndFolloweeId(followerId, follow.getId())) { | |
| throw new ExistFollowException(); | |
| } | |
| } | |
| } | |
| } | |
| public void follow(String followNickname, Long followerId) { | |
| User follower = userRepository.findById(followerId) | |
| .orElseThrow(UserNotFoundException::new); | |
| if (followNickname.equals(follower.getNickName())) { | |
| throw new SameFollowException(); | |
| } | |
| User follow = userRepository.findByNickName(followNickname) | |
| .orElseThrow(UserNotFoundException::new); | |
| if (followRepository.existsByFollowerIdAndFolloweeId(followerId, follow.getId())) { | |
| throw new ExistFollowException(); | |
| } | |
| Follow followEntity = Follow.builder() | |
| .follower(follower) | |
| .followee(follow) | |
| .build(); | |
| followRepository.save(followEntity); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/team/wego/wegobackend/user/application/FollowService.java
around lines 24 to 39, the method only validates conditions but never creates or
persists a Follow entity; add code to construct a new Follow using the follower
and follow User objects (e.g., new Follow(follower, follow) or via a factory
method) and call followRepository.save(...) to persist it, and add an import for
the Follow entity at the top of the file.
| boolean isExistNickname = userRepository.existsByNickName(request.getNickName()); | ||
| if (isExistNickname) { | ||
| throw new SameNicknameException(); | ||
| } |
There was a problem hiding this comment.
현재 사용자를 제외한 닉네임 중복 검증이 필요합니다.
사용자가 자신의 현재 닉네임을 유지하면서 다른 프로필 정보(MBTI, 프로필 메시지 등)만 수정하려고 할 때, 자신의 닉네임도 중복으로 간주되어 SameNicknameException이 발생합니다.
다음과 같이 수정하여 현재 사용자의 닉네임과 다를 때만 중복 검증을 수행하도록 해야 합니다:
if (request.getNickName() != null) {
+ // 현재 닉네임과 다를 때만 중복 검증
+ if (!request.getNickName().equals(user.getNickName())) {
boolean isExistNickname = userRepository.existsByNickName(request.getNickName());
if (isExistNickname) {
throw new SameNicknameException();
}
+ }
user.updateNickName(request.getNickName());
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| boolean isExistNickname = userRepository.existsByNickName(request.getNickName()); | |
| if (isExistNickname) { | |
| throw new SameNicknameException(); | |
| } | |
| if (request.getNickName() != null) { | |
| // 현재 닉네임과 다를 때만 중복 검증 | |
| if (!request.getNickName().equals(user.getNickName())) { | |
| boolean isExistNickname = userRepository.existsByNickName(request.getNickName()); | |
| if (isExistNickname) { | |
| throw new SameNicknameException(); | |
| } | |
| } | |
| user.updateNickName(request.getNickName()); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/team/wego/wegobackend/user/application/UserService.java around
lines 51-54, the current nickname uniqueness check throws SameNicknameException
even when the user keeps their own nickname; modify the logic so the duplicate
check runs only if the requested nickname differs from the current user's
nickname — either compare request.getNickName() with the current user's
getNickName() and skip the repository check when equal, or use a repository
query that excludes the current user (e.g.
existsByNickNameAndIdNot(request.getNickName(), currentUserId)) and throw
SameNicknameException only when that call returns true.
📝 Pull Request
📌 PR 종류
해당하는 항목에 체크해주세요.
✨ 변경 내용
기존 : userId로 팔로우 조회
변경 : nickname으로 팔로우 조회
🔍 관련 이슈
해당 PR이 해결하는 이슈가 있다면 연결해주세요.
🧪 테스트
변경된 기능에 대한 테스트 범위 또는 테스트 결과를 작성해주세요.
닉네임 검증
팔로우
🚨 확인해야 할 사항 (Checklist)
PR을 제출하기 전에 아래 항목들을 확인해주세요.
🙋 기타 참고 사항
리뷰어가 참고하면 좋을 만한 추가 설명이 있다면 적어주세요.
Summary by CodeRabbit
New Features
Bug Fixes
API Changes
✏️ Tip: You can customize this high-level summary in your review settings.