Skip to content

[FEAT] 팔로우 로직 변경 (id -> nickname)#84

Merged
Be-HinD merged 6 commits intomainfrom
feat/follow
Dec 11, 2025
Merged

[FEAT] 팔로우 로직 변경 (id -> nickname)#84
Be-HinD merged 6 commits intomainfrom
feat/follow

Conversation

@Be-HinD
Copy link
Member

@Be-HinD Be-HinD commented Dec 11, 2025

📝 Pull Request

📌 PR 종류

해당하는 항목에 체크해주세요.

  • 기능 추가 (Feature)
  • 버그 수정 (Fix)
  • 문서 수정 (Docs)
  • 코드 리팩터링 (Refactor)
  • 테스트 추가 (Test)
  • 기타 변경 (Chore)

✨ 변경 내용

기존 : userId로 팔로우 조회
변경 : nickname으로 팔로우 조회


🔍 관련 이슈

해당 PR이 해결하는 이슈가 있다면 연결해주세요.


🧪 테스트

변경된 기능에 대한 테스트 범위 또는 테스트 결과를 작성해주세요.

  • 유닛 테스트 추가 / 수정
  • 통합 테스트 검증
  • 수동 테스트 완료

닉네임 검증

image

팔로우

image image

🚨 확인해야 할 사항 (Checklist)

PR을 제출하기 전에 아래 항목들을 확인해주세요.

  • 코드 포매팅 완료
  • 불필요한 파일/코드 제거
  • 로직 검증 완료
  • 프로젝트 빌드 성공
  • 린트/정적 분석 통과 (해당 시)

🙋 기타 참고 사항

리뷰어가 참고하면 좋을 만한 추가 설명이 있다면 적어주세요.

Summary by CodeRabbit

  • New Features

    • 닉네임 중복 검사 기능 추가
    • 닉네임 기반 팔로우 지원
  • Bug Fixes

    • 자기 자신 팔로우 방지
    • 프로필 수정 시 닉네임 중복 검증 및 관련 예외 처리 추가
  • API Changes

    • 팔로우 API 요청 방식 변경: 경로 매개변수 → 쿼리 매개변수 (응답: 201, "팔로우 성공")
    • 테스트 시나리오 업데이트 (팔로우 호출 방식 변경)

✏️ Tip: You can customize this high-level summary in your review settings.

@Be-HinD Be-HinD self-assigned this Dec 11, 2025
@Be-HinD Be-HinD added the 🐞bug Something isn't working label Dec 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

팔로우 기능을 사용자 ID 기반에서 닉네임 기반으로 리팩토링하고, 프로필 업데이트 시 닉네임 중복 검증을 추가하며, 새로운 예외 클래스와 저장소 메서드를 도입하고 관련 API 엔드포인트를 수정했습니다.

Changes

코호트 / 파일 변경 요약
예외 처리 및 에러 코드
src/main/java/team/wego/wegobackend/common/exception/AppErrorCode.java,
src/main/java/team/wego/wegobackend/user/exception/SameNicknameException.java
닉네임 중복에 대한 새로운 에러 코드 ALREADY_EXIST_NICKNAME 추가 및 이를 처리하는 새로운 예외 클래스 SameNicknameException 생성
비즈니스 로직 계층
src/main/java/team/wego/wegobackend/user/application/UserService.java,
src/main/java/team/wego/wegobackend/user/application/FollowService.java
UserService에 닉네임 중복 검증 로직 추가; FollowService의 follow 메서드를 ID 기반에서 닉네임 기반 조회로 변경하고 자기 팔로우 검증 추가
API 계층
src/main/java/team/wego/wegobackend/user/presentation/UserController.java,
src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java
팔로우 엔드포인트를 POST /api/v1/users/follow/{userId}에서 POST /api/v1/users/follow로 변경하고 경로 변수를 요청 파라미터로 수정
저장소 계층
src/main/java/team/wego/wegobackend/user/repository/UserRepository.java
닉네임 기반 조회 및 중복 확인을 위한 두 가지 새로운 메서드 추가: findByNickName(), existsByNickName()
테스트
src/test/http/user/user-api.http
팔로우 API 테스트 엔드포인트를 경로 파라미터 기반에서 쿼리 파라미터 기반으로 변경

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20-25 minutes

  • 주의 필요 영역:
    • FollowService의 follow 메서드에서 저장(save) 작업이 제거된 점 확인 필요
    • UserService와 UserRepository 간의 닉네임 기반 조회 로직 일관성 검증
    • API 엔드포인트 변경에 따른 클라이언트 호출 코드 영향도 확인

Possibly related PRs

Suggested labels

✨enhancement

Poem

🐰 닉네임으로 따라가는 즐거운 팔로우,
중복은 허락하지 않는 검증의 손길,
ID는 물러나고 이름이 주인공,
더 따뜻한 팔로우의 시대가 열렸네! 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 주요 변경사항을 명확하게 설명하며, 팔로우 로직이 사용자 ID에서 닉네임 기반으로 변경되었음을 정확히 나타냅니다.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/follow

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 521e785 and 5057223.

📒 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 대신 닉네임으로 자기 자신을 팔로우하는 것을 방지하는 로직이 정확합니다.

Comment on lines +24 to +39
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

팔로우 관계 저장 로직이 누락되었습니다.

검증 로직만 수행하고 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.

Suggested change
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.

Comment on lines +51 to +54
boolean isExistNickname = userRepository.existsByNickName(request.getNickName());
if (isExistNickname) {
throw new SameNicknameException();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

현재 사용자를 제외한 닉네임 중복 검증이 필요합니다.

사용자가 자신의 현재 닉네임을 유지하면서 다른 프로필 정보(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.

Suggested change
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.

@Be-HinD Be-HinD merged commit f8da740 into main Dec 11, 2025
1 check passed
@Be-HinD Be-HinD deleted the feat/follow branch December 11, 2025 15:50
@github-project-automation github-project-automation bot moved this from Backlog to Done in WeGo-Together Backend Dec 11, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 15, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant