Skip to content

REFACTOR: 팔로우 이벤트 로직 리팩토링#216

Merged
Be-HinD merged 1 commit intomainfrom
refactor/follow-event
Jan 26, 2026
Merged

REFACTOR: 팔로우 이벤트 로직 리팩토링#216
Be-HinD merged 1 commit intomainfrom
refactor/follow-event

Conversation

@Be-HinD
Copy link
Member

@Be-HinD Be-HinD commented Jan 23, 2026

📝 Pull Request

📌 PR 종류

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

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

✨ 변경 내용

팔로우 이벤트 발행 로직에 대한 리팩토링 수행했습니다.

  1. 이벤트 객체명을 도메인 이벤트 성격이 드러나도록 UserFollowEvent로 변경했습니다.
  2. 기존 이벤트 파라메터로 User 엔티티를 받던 부분을 DTO로 변경했습니다. (영속성 관련 문제 회피 및 트랜잭션 영향 감소를 위해)
  3. listener -> dispatch 호출을 없애고 listener에서 로직 처리를 하도록 변경했습니다. (단건 발행이라 dispatch를 타면서까지 복잡성을 늘릴 필요가 없다고 판단)

🔍 관련 이슈


🧪 테스트

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

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

직접적인 http 테스트를 통해 actor/receiver 데이터 비교 진행했습니다.
image


🚨 확인해야 할 사항 (Checklist)

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

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

🙋 기타 참고 사항

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

Summary by CodeRabbit

릴리스 노트

  • Refactor
    • 팔로우 알림 시스템을 재구성하여 알림 전달의 안정성을 개선하였습니다.
    • 실시간 알림 처리 방식을 최적화하여 성능을 향상시켰습니다.

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

- 이벤트 객체명 변경(FollowEvent -> UserFollowEvent)
- 이벤트 객체 필드 변경(Entity -> DTO)
- dispatch에서 리스너로 처리 위치 변경 (단순화)
@Be-HinD Be-HinD self-assigned this Jan 23, 2026
@Be-HinD Be-HinD added the ✨enhancement New feature or request label Jan 23, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

워크스루

팔로우 알림 처리 로직이 직접 디스패처 호출에서 이벤트 기반 리스너 패턴으로 변경되었습니다. 기존 FollowEvent를 ID 기반의 UserFollowEvent로 대체하고, 이벤트 리스너에서 사용자 데이터를 로드한 후 알림을 직접 생성 및 저장합니다.

변경 사항

코호트 / 파일 변경 요약
이벤트 페이로드 개선
src/main/java/team/wego/wegobackend/user/application/event/FollowEvent.java, src/main/java/team/wego/wegobackend/user/application/event/UserFollowEvent.java
전체 User 엔터티를 담는 FollowEvent 제거; ID 기반의 새로운 불변 레코드 UserFollowEvent(Long followerId, Long followId) 추가로 메모리 효율성 및 느슨한 결합 개선
팔로우 서비스 이벤트 발행
src/main/java/team/wego/wegobackend/user/application/FollowService.java
이벤트 타입을 FollowEvent에서 UserFollowEvent로 변경; 페이로드를 User 객체에서 ID 기반으로 업데이트
이벤트 리스너 알림 생성
src/main/java/team/wego/wegobackend/user/application/listener/FollowEventListener.java
디스패처 호출 제거 및 리스너 내에서 직접 알림 생성·저장·SSE 발송 로직 구현; userRepository, notificationRepository, sseEmitterService 의존성 추가; @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)@Transactional(propagation = Propagation.REQUIRES_NEW) 적용
디스패처 메서드 제거
src/main/java/team/wego/wegobackend/notification/application/dispatcher/NotificationDispatcher.java
팔로우 전용 dispatch(User follower, User follow) 메서드 제거
테스트 요청 업데이트
src/test/http/noti/noti-api.http
팔로우 요청 닉네임을 receiver에서 1등으로 변경

예상 코드 리뷰 난이도

🎯 3 (Moderate) | ⏱️ ~20 분

관련 PR 목록

  • FIX: 팔로우 알림 id 할당 이슈 조치 #215: 동일한 팔로우 알림 플로우에서 notificationRepository.flush() 및 트랜잭션 경계 처리를 추가하는 PR로, 본 PR의 리스너 기반 알림 저장과 직접 연관됨
  • [FEAT] 알림 도메인 요구사항 개발 #191: 동일한 NotificationDispatcher.java를 수정하며 디스패처 메서드 변경 및 SSE 호출 지점을 변경하는 PR와 코드 레벨에서 직접 관련됨
  • [FEAT] SSE 알림 로직 개발 #111: 팔로우 알림 흐름을 이벤트 기반으로 재구성하고 리스너 내에서 NotificationRepositorySseEmitterService를 통해 알림 관리하는 방식을 본 PR과 동일하게 도입함

🐰 이제 이벤트의 흐름을 따라
ID 가볍게 날아다니고
리스너에서 알림이 태어나
저장되고 흘러가네
팔로우의 마법, 더욱 깔끔해 ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경 사항의 주요 목적을 명확하게 반영합니다. 팔로우 이벤트 로직 리팩토링이라는 핵심 내용이 간결하고 구체적으로 표현되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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: 1

🤖 Fix all issues with AI agents
In `@src/test/http/noti/noti-api.http`:
- Line 35: The follow target nickname in the HTTP test uses followNickname=1등
but the script only creates the receiver user, so the test can 404; either
change the followNickname to the receiver's actual nickname (the created user)
or add a setup request that creates a user with nickname "1등" before the POST
/api/v1/users/follow call; update the test to ensure the created user's nickname
matches the followNickname parameter (reference the followNickname query param
and the receiver user creation step).


### 팔로우 요청
POST http://localhost:8080/api/v1/users/follow?followNickname=receiver
POST http://localhost:8080/api/v1/users/follow?followNickname=1등
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

팔로우 대상 닉네임이 사전 생성 사용자와 불일치합니다.
이 스크립트에서는 receiver만 가입시키는데 followNickname=1등이면 초기 DB에서 404가 날 수 있습니다. 닉네임을 맞추거나 1등 사용자 생성 단계를 추가해 주세요.

💡 수정 제안
-POST http://localhost:8080/api/v1/users/follow?followNickname=1등
+POST http://localhost:8080/api/v1/users/follow?followNickname=receiver
📝 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
POST http://localhost:8080/api/v1/users/follow?followNickname=1등
POST http://localhost:8080/api/v1/users/follow?followNickname=receiver
🤖 Prompt for AI Agents
In `@src/test/http/noti/noti-api.http` at line 35, The follow target nickname in
the HTTP test uses followNickname=1등 but the script only creates the receiver
user, so the test can 404; either change the followNickname to the receiver's
actual nickname (the created user) or add a setup request that creates a user
with nickname "1등" before the POST /api/v1/users/follow call; update the test to
ensure the created user's nickname matches the followNickname parameter
(reference the followNickname query param and the receiver user creation step).

@Be-HinD Be-HinD merged commit f8bd722 into main Jan 26, 2026
1 check passed
@Be-HinD Be-HinD deleted the refactor/follow-event branch January 26, 2026 11:51
@github-project-automation github-project-automation bot moved this from Backlog to Done in WeGo-Together Backend Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant