Skip to content

[FEAT] 회원 모임 참여와 생성 반정규화에 따른 수정#107

Merged
LimdaeIl merged 4 commits intomainfrom
feat/count-user
Dec 14, 2025
Merged

[FEAT] 회원 모임 참여와 생성 반정규화에 따른 수정#107
LimdaeIl merged 4 commits intomainfrom
feat/count-user

Conversation

@LimdaeIl
Copy link
Collaborator

@LimdaeIl LimdaeIl commented Dec 14, 2025

📝 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 Dec 14, 2025
@LimdaeIl LimdaeIl added the ✨enhancement New feature or request label Dec 14, 2025
Copilot AI review requested due to automatic review settings December 14, 2025 05:58
@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

Caution

Review failed

The pull request is closed.

🔍 변경 사항 분석

📋 개요

그룹 생성 및 참여 시 사용자의 참여/생성 횟수를 추적하기 위해 GroupService의 메서드를 리팩토링하고, 그룹 사용자 저장소에 쿼리 메서드를 추가했습니다. 테스트 데이터 타임스탬프도 업데이트되었습니다.

📊 변경 사항 목록

계층 / 파일 변경 요약
서비스 계층 리팩토링
src/main/java/team/wego/wegobackend/group/application/service/GroupService.java
saveHostAsGroupUser 메서드를 registerHost로 이름 변경; 그룹 생성 시 호스트의 생성 횟수 증가 로직 추가; attendGroup에서 사용자 첫 참여 시 참여 횟수 증가 로직 추가; 그룹 참석자 참여 횟수 감소 헬퍼 메서드 decreaseJoinedCountForAttenders(Group) 추가
저장소 쿼리 확장
src/main/java/team/wego/wegobackend/group/domain/repository/GroupUserRepository.java
그룹과 상태로 그룹 사용자를 조회하고 연관된 사용자를 즉시 로딩하는 JPQL 쿼리 메서드 findAllByGroupAndStatusFetchUser(Group, GroupUserStatus) 추가
테스트 데이터 업데이트
src/test/http/group/group-cancel.http
그룹 생성 페이로드의 startTimeendTime을 2025-12-11에서 2026-12-11로 변경

⏱️ 코드 리뷰 예상 시간

🎯 3 (중간) | ⏱️ ~20분

추가 검토 권장 사항:

  • decreaseJoinedCountForAttenders(Group) 메서드가 다른 두 위치에서 선언되어 있는지 확인 필요 (중복 선언 여부)
  • 그룹 사용자의 참여/생성 횟수 증감 로직이 모든 흐름(생성, 참여, 재참여, 탈퇴)에서 일관되게 적용되는지 검증
  • findAllByGroupAndStatusFetchUser 메서드의 N+1 쿼리 문제 해결 여부 확인

🔗 관련 가능성 있는 PR

  • [FEAT] 모임 상세 조회 구현 #50: 그룹 참석 흐름(attendGroup 및 관련 헬퍼 로직)과 참석자 조회를 위한 GroupUserRepository 수정이 동일하게 적용되어 있어 관련이 있습니다.

🐰 변경을 축하하는 토끼의 시

참여도 세고, 생성도 세는 우리의 모임 🎉
반정규화로 카운트를 기록하네,
호스트도 멤버도 역할 분담,
그룹 통계가 더욱 정확해져,
WeGo의 여정이 빛나간다! ✨

✨ 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/count-user

📜 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 40ae502 and 97b896b.

📒 Files selected for processing (3)
  • src/main/java/team/wego/wegobackend/group/application/service/GroupService.java (4 hunks)
  • src/main/java/team/wego/wegobackend/group/domain/repository/GroupUserRepository.java (2 hunks)
  • src/test/http/group/group-cancel.http (1 hunks)

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 173d785 into main Dec 14, 2025
4 of 5 checks passed
@LimdaeIl LimdaeIl deleted the feat/count-user branch December 14, 2025 05:58
@github-project-automation github-project-automation bot moved this from Backlog to Done in WeGo-Together Backend Dec 14, 2025
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 pull request introduces denormalization of group participation and creation counts in the User entity. The changes aim to maintain counters for how many groups a user has joined (groupJoinedCount) and created (groupCreatedCount), eliminating the need for aggregation queries to retrieve these statistics.

Key Changes:

  • Added increment logic for groupJoinedCount and groupCreatedCount when users create or join groups for the first time
  • Introduced a new repository query method findAllByGroupAndStatusFetchUser to efficiently fetch group users with user data
  • Updated HTTP test data to use future dates (2026 instead of 2025)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/test/http/group/group-cancel.http Updated test data dates from 2025 to 2026 to use future dates
src/main/java/team/wego/wegobackend/group/domain/repository/GroupUserRepository.java Added fetch join query method to retrieve group users with their user entities
src/main/java/team/wego/wegobackend/group/application/service/GroupService.java Implemented counter increments for group creation and first-time joins; added helper method for batch counter decrements (currently unused)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +65 to +66
"startTime": "2026-12-11T19:00:00",
"endTime": "2026-12-11T21:00:00",
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

While updating the hardcoded dates from 2025 to 2026 fixes the immediate issue of past dates, consider using relative dates in test data to prevent this maintenance burden in the future. For example, you could use a date calculation like "now + 30 days" to ensure test data always uses future dates without manual updates.

Copilot uses AI. Check for mistakes.
Comment on lines +583 to +588
private void decreaseJoinedCountForAttenders(Group group) {
List<GroupUser> attenders = groupUserRepository.findAllByGroupAndStatusFetchUser(group,
ATTEND);

attenders.forEach(gu -> gu.getUser().decreaseGroupJoinedCount());
}
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The method decreaseJoinedCountForAttenders is defined but never called in the deleteGroup method above (lines 556-581). When a group is deleted, all attending users should have their groupJoinedCount decremented, and the host should have their groupCreatedCount decremented. Currently, these counters will become inaccurate when groups are deleted. Call this method before deleting the group, and also add logic to decrease the host's groupCreatedCount.

Copilot uses AI. Check for mistakes.
""")
List<GroupUser> findAllByGroupAndStatusFetchUser(
@Param("group") Group group,
@Param("status") GroupUserStatus status);
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The new query method findAllByGroupAndStatusFetchUser is added but appears to only be used in the decreaseJoinedCountForAttenders method, which itself is not being called anywhere in the codebase. This suggests that the implementation for decreasing counters when groups are deleted is incomplete. Ensure this method is properly utilized in the delete group workflow.

Suggested change
@Param("status") GroupUserStatus status);
@Param("status") GroupUserStatus status);
/**
* Returns the list of users who are attending the given group.
* Intended for use in the group deletion workflow to update user joined counts.
* The caller should decrement the joined count for each user and persist the changes.
*/
default List<User> findAttendingUsersForGroup(Group group) {
return findAllByGroupAndStatusFetchUser(group, GroupUserStatus.ATTENDING)
.stream()
.map(GroupUser::getUser)
.toList();
}

Copilot uses AI. Check for mistakes.
Comment on lines +116 to 122
private void registerHost(Group group, User host) {
GroupUser groupUser = GroupUser.create(group, host, GroupRole.HOST);
groupUserRepository.save(groupUser);

host.increaseGroupJoinedCount();
host.increaseGroupCreatedCount();
}
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The method name registerHost could be more descriptive. Consider renaming it to something like saveHostAndIncrementCounters or registerHostWithCounters to make it clear that this method not only saves the host as a GroupUser but also increments denormalized counters. This would make the side effects more obvious to future maintainers.

Copilot uses AI. Check for mistakes.
Comment on lines +263 to +268
// 유니크 참여 카운트는 "처음 참여"일 때만 올리기
if (groupUser == null) {
// 처음 참여
GroupUser newGroupUser = GroupUser.create(group, member, GroupRole.MEMBER);
groupUserRepository.save(newGroupUser);

member.increaseGroupJoinedCount();
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The comment mentions incrementing a "유니크 참여 카운트" (unique participation count) but the counter being incremented is simply called groupJoinedCount. Consider adding more comprehensive documentation about the denormalization strategy, such as explaining that the counter tracks the number of unique groups a user has ever joined (not re-joins), and why this distinction matters for the business logic.

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