-
Notifications
You must be signed in to change notification settings - Fork 0
모임 참여 카운트와 정렬 순서 개선 #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
모임 참여 카운트와 정렬 순서 개선 #206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |||||
| import team.wego.wegobackend.group.v2.domain.repository.GroupUserV2QueryRepository; | ||||||
| import team.wego.wegobackend.group.v2.domain.repository.GroupUserV2Repository; | ||||||
| import team.wego.wegobackend.group.v2.domain.repository.GroupV2Repository; | ||||||
| import team.wego.wegobackend.user.domain.User; | ||||||
| import team.wego.wegobackend.user.repository.UserRepository; | ||||||
|
|
||||||
| @Slf4j | ||||||
|
|
@@ -51,9 +52,8 @@ public class GroupV2AttendanceService { | |||||
| @Transactional | ||||||
| public AttendanceGroupV2Response attend(Long userId, Long groupId, String message) { | ||||||
| // 회원 체크 | ||||||
| if (userId == null) { | ||||||
| throw new GroupException(GroupErrorCode.USER_ID_NULL); | ||||||
| } | ||||||
| User member = userRepository.findById(userId) | ||||||
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL)); | ||||||
|
|
||||||
| // 모임 체크: for update로 가져오기 | ||||||
| GroupV2 group = groupV2Repository.findByIdForUpdate(groupId) | ||||||
|
|
@@ -119,7 +119,8 @@ public AttendanceGroupV2Response attend(Long userId, Long groupId, String messag | |||||
| } | ||||||
|
|
||||||
| // FULL 자동 전환 | ||||||
| long newCount = groupUserV2Repository.countByGroupIdAndStatus(groupId, GroupUserV2Status.ATTEND); | ||||||
| long newCount = groupUserV2Repository.countByGroupIdAndStatus(groupId, | ||||||
| GroupUserV2Status.ATTEND); | ||||||
|
|
||||||
| if (newCount == group.getMaxParticipants() | ||||||
| && group.getStatus() == GroupV2Status.RECRUITING) { | ||||||
|
|
@@ -132,6 +133,8 @@ public AttendanceGroupV2Response attend(Long userId, Long groupId, String messag | |||||
| eventPublisher.publishEvent( | ||||||
| new GroupJoinedEvent(groupId, group.getHost().getId(), userId)); | ||||||
|
|
||||||
| member.increaseGroupJoinedCount(); | ||||||
|
||||||
|
|
||||||
| return AttendanceGroupV2Response.of(group, newCount, membership); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -298,6 +301,11 @@ public GroupUserV2StatusResponse approve(Long approverUserId, Long groupId, | |||||
| group.changeStatus(GroupV2Status.FULL); | ||||||
| } | ||||||
|
|
||||||
| User member = userRepository.findById(targetUserId) | ||||||
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId)); | ||||||
|
||||||
| .orElseThrow(() -> new GroupException(GroupErrorCode.USER_ID_NULL, targetUserId)); | |
| .orElseThrow(() -> new GroupException(GroupErrorCode.GROUP_USER_NOT_FOUND, targetUserId)); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
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.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -202,11 +202,14 @@ public CreateGroupV2Response create(Long userId, CreateGroupV2Request request) { | |||||||||||||
|
|
||||||||||||||
| groupCreateCooldownService.acquireOrThrowWithRollbackRelease(userId, COOL_DOWN_SECONDS); | ||||||||||||||
|
|
||||||||||||||
| // 회원 조회 | ||||||||||||||
| // 회원 조회 후 카운트 | ||||||||||||||
| User host = userRepository.findById(userId) | ||||||||||||||
| .orElseThrow(() -> new GroupException(GroupErrorCode.HOST_USER_NOT_FOUND, userId) | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| // 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. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,4 +64,24 @@ List<Long> findUserIdsByGroupIdAndStatuses( | |||||||||||||||||||
| @Modifying(clearAutomatically = true, flushAutomatically = true) | ||||||||||||||||||||
| @Query("delete from GroupUserV2 gu where gu.user.id = :userId") | ||||||||||||||||||||
| void deleteByUserId(@Param("userId") Long userId); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @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); | ||||||||||||||||||||
|
Comment on lines
+68
to
+75
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @Query(""" | ||||||||||||||||||||
| select gu | ||||||||||||||||||||
| from GroupUserV2 gu | ||||||||||||||||||||
| join fetch gu.user u | ||||||||||||||||||||
| where gu.group.id = :groupId | ||||||||||||||||||||
| and gu.status = 'ATTEND' | ||||||||||||||||||||
| order by gu.joinedAt asc | ||||||||||||||||||||
| """) | ||||||||||||||||||||
| List<GroupUserV2> findAttendByGroupIdOrderByJoinedAtAscWithUser(@Param("groupId") Long groupId); | ||||||||||||||||||||
|
Comment on lines
+82
to
+85
|
||||||||||||||||||||
| 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); |
There was a problem hiding this comment.
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.