Skip to content

모임 참여 카운트와 정렬 순서 개선#206

Merged
LimdaeIl merged 1 commit intomainfrom
feat/group-count
Jan 5, 2026
Merged

모임 참여 카운트와 정렬 순서 개선#206
LimdaeIl merged 1 commit intomainfrom
feat/group-count

Conversation

@LimdaeIl
Copy link
Collaborator

@LimdaeIl LimdaeIl commented Jan 5, 2026

📝 Pull Request

📌 PR 종류

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

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

✨ 변경 내용

그룹 생성 및 가입 이벤트에 대한 카운터를 증가시켜 사용자 참여 추적 기능을 향상시킵니다. 이를 통해 사용자 활동 및 플랫폼 전반의 성장을 더욱 효과적으로 분석할 수 있습니다.

호스트 보기와 멤버 보기에 맞춰 그룹 사용자 정보 가져오기 로직을 ​​조정하여,
그룹 내 사용자 역할에 따라 데이터 검색을 최적화합니다.

🔍 관련 이슈

🧪 테스트

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

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

🚨 확인해야 할 사항 (Checklist)

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

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

🙋 기타 참고 사항

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

Summary by CodeRabbit

버그 수정

  • 그룹 가입 및 생성 시 사용자 통계가 정확하게 추적됩니다
  • 그룹 멤버 조회 로직이 개선되어 사용자 권한에 따라 적절한 데이터를 표시합니다

리팩토링

  • 그룹 관리 서비스 내부 로직이 개선되었습니다

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

그룹 생성 및 가입 이벤트에 대한 카운터를 증가시켜 사용자 참여 추적 기능을 향상시킵니다.
이를 통해 사용자 활동 및 플랫폼 전반의 성장을 더욱 효과적으로 분석할 수 있습니다.

호스트 보기와 멤버 보기에 맞춰 그룹 사용자 정보 가져오기 로직을 ​​조정하여,
그룹 내 사용자 역할에 따라 데이터 검색을 최적화합니다.
@LimdaeIl LimdaeIl self-assigned this Jan 5, 2026
Copilot AI review requested due to automatic review settings January 5, 2026 02:16
@LimdaeIl LimdaeIl added the ✨enhancement New feature or request label Jan 5, 2026
@LimdaeIl LimdaeIl moved this from Backlog to In progress in WeGo-Together Backend Jan 5, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 5, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

모임 참여, 승인, 생성 시 사용자의 그룹 가입 카운트를 증가시킵니다. 그룹 상세 조회 시 요청 사용자가 호스트인지 여부에 따라 다른 저장소 쿼리를 사용하여 멤버를 조회합니다.

Changes

집합 / 파일 변경 사항
카운트 추적 로직
src/main/java/team/wego/wegobackend/group/v2/application/service/GroupV2AttendanceService.java
userId 널 체크를 userRepository 조회로 변경. attend 성공 후 increaseGroupJoinedCount() 호출. approve 경로에서도 targetUserId 조회 후 카운트 증가.
그룹 서비스 카운트 및 조회
src/main/java/team/wego/wegobackend/group/v2/application/service/GroupV2Service.java
create 메서드에서 호스트 생성/참여 카운터 증가. getGroup에서 isHost 여부에 따라 조건부 저장소 쿼리 호출 (findByGroupIdOrderByJoinedAtAscWithUser vs findAttendByGroupIdOrderByJoinedAtAscWithUser).
저장소 쿼리 메서드 추가
src/main/java/team/wego/wegobackend/group/v2/domain/repository/GroupUserV2Repository.java
2개 메서드 추가: findByGroupIdOrderByJoinedAtAscWithUser (모든 그룹 멤버), findAttendByGroupIdOrderByJoinedAtAscWithUser (ATTEND 상태 멤버만). 모두 User를 eager loading하고 joinedAt으로 정렬.

Sequence Diagram

sequenceDiagram
    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
Loading
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
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

Poem

🐰 숫자 셈하는 토끼가 왔네요!
참여할 때마다 카운트 쏙쏙,
호스트 눈에는 모두 보이고,
멤버 눈에는 참여자만 보이지요.
정렬 순서도 깔끔하게 ✨

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent 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 dc20f5a and 611e3a1.

📒 Files selected for processing (3)
  • src/main/java/team/wego/wegobackend/group/v2/application/service/GroupV2AttendanceService.java
  • src/main/java/team/wego/wegobackend/group/v2/application/service/GroupV2Service.java
  • src/main/java/team/wego/wegobackend/group/v2/domain/repository/GroupUserV2Repository.java

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.

@LimdaeIl LimdaeIl merged commit 4b8bdc6 into main Jan 5, 2026
4 of 5 checks passed
@LimdaeIl LimdaeIl deleted the feat/group-count branch January 5, 2026 02:17
@github-project-automation github-project-automation bot moved this from In progress to Done in WeGo-Together Backend Jan 5, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() and increaseGroupCreatedCount() calls at key join/creation points
  • Introduces two new repository methods that fetch users ordered by joinedAt with eager loading
  • Modifies the getGroup method 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)
);

Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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

Copilot uses AI. Check for mistakes.
throw new GroupException(GroupErrorCode.USER_ID_NULL);
}
User member = userRepository.findById(userId)
.orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL));
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
.orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL));
.orElseThrow(() -> new GroupException(GroupErrorCode.GROUP_USER_NOT_FOUND));

Copilot uses AI. Check for mistakes.
}

User member = userRepository.findById(targetUserId)
.orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId));
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
.orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId));
.orElseThrow(() -> new GroupException(GroupErrorCode.GROUP_USER_NOT_FOUND, targetUserId));

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +85
and gu.status = 'ATTEND'
order by gu.joinedAt asc
""")
List<GroupUserV2> findAttendByGroupIdOrderByJoinedAtAscWithUser(@Param("groupId") Long groupId);
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
eventPublisher.publishEvent(
new GroupJoinedEvent(groupId, group.getHost().getId(), userId));

member.increaseGroupJoinedCount();
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
User member = userRepository.findById(targetUserId)
.orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId));

member.increaseGroupJoinedCount();
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +75
@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);
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

[FEAT] 모임 참여 카운트와 정렬 순서 개선

1 participant