Conversation
그룹 생성 및 가입 이벤트에 대한 카운터를 증가시켜 사용자 참여 추적 기능을 향상시킵니다. 이를 통해 사용자 활동 및 플랫폼 전반의 성장을 더욱 효과적으로 분석할 수 있습니다. 호스트 보기와 멤버 보기에 맞춰 그룹 사용자 정보 가져오기 로직을 조정하여, 그룹 내 사용자 역할에 따라 데이터 검색을 최적화합니다.
|
Caution Review failedThe pull request is closed. Walkthrough모임 참여, 승인, 생성 시 사용자의 그룹 가입 카운트를 증가시킵니다. 그룹 상세 조회 시 요청 사용자가 호스트인지 여부에 따라 다른 저장소 쿼리를 사용하여 멤버를 조회합니다. Changes
Sequence DiagramsequenceDiagram
actor Client
participant GroupV2AttendanceService as GroupV2AttendanceService
participant UserRepository
participant GroupUserV2Repository
participant User
Client->>GroupV2AttendanceService: attend(groupId, userId)
GroupV2AttendanceService->>UserRepository: findById(userId)
alt User Found
UserRepository-->>GroupV2AttendanceService: User
GroupV2AttendanceService->>GroupUserV2Repository: save(groupUser)
GroupV2AttendanceService->>User: increaseGroupJoinedCount()
GroupV2AttendanceService-->>Client: AttendResponse
else User Not Found
UserRepository-->>GroupV2AttendanceService: null
GroupV2AttendanceService-->>Client: USER_ID_NULL Error
end
Client->>GroupV2AttendanceService: approve(groupId, targetUserId, ...)
GroupV2AttendanceService->>UserRepository: findById(targetUserId)
alt User Found
UserRepository-->>GroupV2AttendanceService: User
GroupV2AttendanceService->>User: increaseGroupJoinedCount()
GroupV2AttendanceService-->>Client: ApprovalResponse
else User Not Found
UserRepository-->>GroupV2AttendanceService: null
GroupV2AttendanceService-->>Client: USER_ID_NULL Error
end
sequenceDiagram
actor Client
participant GroupV2Service
participant GroupUserV2Repository
participant User
Client->>GroupV2Service: getGroup(groupId, userId)
GroupV2Service->>GroupV2Service: isHost = (group.hostId == userId)
alt User is Host
GroupV2Service->>GroupUserV2Repository: findByGroupIdOrderByJoinedAtAscWithUser(groupId)
GroupUserV2Repository-->>GroupV2Service: [모든 GroupUser + User 포함]
else User is Not Host
GroupV2Service->>GroupUserV2Repository: findAttendByGroupIdOrderByJoinedAtAscWithUser(groupId)
GroupUserV2Repository-->>GroupV2Service: [ATTEND 상태 GroupUser + User 포함]
end
GroupV2Service-->>Client: GroupDetailResponse
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Poem
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
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.
Pull request overview
This PR enhances group participation tracking by adding counter increments for group creation and join events, and improves data retrieval by introducing sorted queries that differentiate between host and member views.
- Adds
increaseGroupJoinedCount()andincreaseGroupCreatedCount()calls at key join/creation points - Introduces two new repository methods that fetch users ordered by
joinedAtwith eager loading - Modifies the
getGroupmethod to return different user lists based on whether the requester is the host (all users) or a member (only ATTEND status users)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| GroupUserV2Repository.java | Added two new query methods for fetching group users ordered by joinedAt: one for all users and one filtered by ATTEND status |
| GroupV2Service.java | Incremented both groupCreatedCount and groupJoinedCount when a host creates a group; modified getGroup to conditionally fetch users based on host/member role |
| GroupV2AttendanceService.java | Added groupJoinedCount increments in attend and approve methods; changed user lookup to use findById with better error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| User host = userRepository.findById(userId) | ||
| .orElseThrow(() -> new GroupException(GroupErrorCode.HOST_USER_NOT_FOUND, userId) | ||
| ); | ||
|
|
There was a problem hiding this comment.
When a host creates a group, both groupCreatedCount and groupJoinedCount are incremented. While this may be intentional (the host both creates and joins the group), it's worth noting that if the host later deletes the group or leaves (though the code prevents hosts from leaving), there should be corresponding decrements for both counters. Currently, no decrement logic exists for group deletion or other scenarios. Consider documenting this behavior or implementing symmetric decrement logic.
| // NOTE: | |
| // - The host both creates and joins the group, so we increment both counters here. | |
| // - These counters are intended as lifetime statistics (total created / total joined) | |
| // and are not decremented on group deletion or when a host leaves. |
| throw new GroupException(GroupErrorCode.USER_ID_NULL); | ||
| } | ||
| User member = userRepository.findById(userId) | ||
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL)); |
There was a problem hiding this comment.
The error code USER_ID_NULL is being used when a user is not found in the database (via findById), but the error message "모임: 회원 ID가 null 입니다." (The member ID is null) is misleading in this context. The userId parameter is not null - it's being passed to findById. The actual issue is that the user doesn't exist in the database. Consider using a more appropriate error code like GROUP_USER_NOT_FOUND or creating a new error code that accurately reflects that the user doesn't exist.
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL)); | |
| .orElseThrow(() -> new GroupException(GroupErrorCode.GROUP_USER_NOT_FOUND)); |
| } | ||
|
|
||
| User member = userRepository.findById(targetUserId) | ||
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId)); |
There was a problem hiding this comment.
The error code USER_ID_NULL is being used when a user is not found in the database (via findById), but the error message "모임: 회원 ID가 null 입니다." (The member ID is null) is misleading in this context. The userId parameter is not null - it's being passed to findById. The actual issue is that the user doesn't exist in the database. Consider using a more appropriate error code like GROUP_USER_NOT_FOUND or creating a new error code that accurately reflects that the user doesn't exist.
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId)); | |
| .orElseThrow(() -> new GroupException(GroupErrorCode.GROUP_USER_NOT_FOUND, targetUserId)); |
| and gu.status = 'ATTEND' | ||
| order by gu.joinedAt asc | ||
| """) | ||
| List<GroupUserV2> findAttendByGroupIdOrderByJoinedAtAscWithUser(@Param("groupId") Long groupId); |
There was a problem hiding this comment.
Using a hard-coded string literal 'ATTEND' in the JPQL query instead of a parameterized value. This is inconsistent with other queries in this file (like findUserIdsByGroupIdAndStatus at line 37) that use proper parameters for status values. Consider using a parameter for the status value to maintain consistency, improve type safety, and prevent potential typos.
| and gu.status = 'ATTEND' | |
| order by gu.joinedAt asc | |
| """) | |
| List<GroupUserV2> findAttendByGroupIdOrderByJoinedAtAscWithUser(@Param("groupId") Long groupId); | |
| and gu.status = :status | |
| order by gu.joinedAt asc | |
| """) | |
| List<GroupUserV2> findAttendByGroupIdOrderByJoinedAtAscWithUser(@Param("groupId") Long groupId, | |
| @Param("status") GroupUserV2Status status); |
| eventPublisher.publishEvent( | ||
| new GroupJoinedEvent(groupId, group.getHost().getId(), userId)); | ||
|
|
||
| member.increaseGroupJoinedCount(); |
There was a problem hiding this comment.
The groupJoinedCount is incremented when a user re-attends a group (after leaving, getting kicked, rejected, or cancelled), but there is no corresponding decrement when the user leaves the group. In the 'left' method at line 173-226, when a user's status changes to LEFT, the counter is not decremented. This will cause the counter to continuously increase even when users leave and re-join the same group multiple times, leading to inaccurate tracking of actual group participation. Consider adding member.decreaseGroupJoinedCount() in the 'left' method when the status changes to LEFT.
| User member = userRepository.findById(targetUserId) | ||
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId)); | ||
|
|
||
| member.increaseGroupJoinedCount(); |
There was a problem hiding this comment.
The groupJoinedCount is incremented when a user is approved to join a group, but similar to the attend method, there is no corresponding decrement when users leave. When a user who was approved later leaves the group (via the 'left' method or gets kicked), their counter should be decremented to maintain accuracy. This same issue affects the kick scenario as well - users who are kicked from a group should have their groupJoinedCount decremented.
| @Query(""" | ||
| select gu | ||
| from GroupUserV2 gu | ||
| join fetch gu.user u | ||
| where gu.group.id = :groupId | ||
| order by gu.joinedAt asc | ||
| """) | ||
| List<GroupUserV2> findByGroupIdOrderByJoinedAtAscWithUser(@Param("groupId") Long groupId); |
There was a problem hiding this comment.
The sorting by joinedAt may produce unexpected results when users re-join a group. The joinedAt field is updated to the current time when a user re-attends a group (via reAttend() at line 84 in GroupUserV2.java or requestJoin() at line 164). This means users who leave and re-join will appear at the end of the list, potentially after users who joined later originally. If the intent is to sort by the original join time regardless of re-joins, consider using a separate field for the original join timestamp or clarify the expected behavior in comments.
📝 Pull Request
📌 PR 종류
해당하는 항목에 체크해주세요.
✨ 변경 내용
그룹 생성 및 가입 이벤트에 대한 카운터를 증가시켜 사용자 참여 추적 기능을 향상시킵니다. 이를 통해 사용자 활동 및 플랫폼 전반의 성장을 더욱 효과적으로 분석할 수 있습니다.
호스트 보기와 멤버 보기에 맞춰 그룹 사용자 정보 가져오기 로직을 조정하여,
그룹 내 사용자 역할에 따라 데이터 검색을 최적화합니다.
🔍 관련 이슈
🧪 테스트
변경된 기능에 대한 테스트 범위 또는 테스트 결과를 작성해주세요.
🚨 확인해야 할 사항 (Checklist)
PR을 제출하기 전에 아래 항목들을 확인해주세요.
🙋 기타 참고 사항
리뷰어가 참고하면 좋을 만한 추가 설명이 있다면 적어주세요.
Summary by CodeRabbit
버그 수정
리팩토링
✏️ Tip: You can customize this high-level summary in your review settings.