diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/repository/groupInviteRepository/GroupInviteRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/repository/groupInviteRepository/GroupInviteRepository.java index e429c0346..009600258 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/repository/groupInviteRepository/GroupInviteRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/repository/groupInviteRepository/GroupInviteRepository.java @@ -12,8 +12,17 @@ public interface GroupInviteRepository extends Repository, void save(GroupInvite groupInvite); - int deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId(Long groupId, Long groupOwnerId, - Long groupMemberId); + @Query("delete from GroupInvite gi " + + "where gi.group.id =:groupId " + + "and gi.groupOwner.id =:groupOwnerId " + + "and gi.groupMember.id =:groupMemberId" + ) + @Modifying + int deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + @Param("groupId") Long groupId, + @Param("groupOwnerId") Long groupOwnerId, + @Param("groupMemberId") Long groupMemberId + ); @Query("delete from GroupInvite gi where gi.id in :groupInviteIds") @Modifying diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandService.java index 727a73fe8..5f9e3bbc1 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandService.java @@ -75,7 +75,11 @@ public GroupAcceptNotificationDto acceptGroupInvite(final Long memberId, final L final Long totalGroupMemberCount = groupRepository.getTotalGroupMemberCount(groupId) .orElseThrow(GroupNotFoundException::new); + final Long groupOwnerId = memberGroupRepository.findGroupOwnerId(groupId) + .orElseThrow(GroupNotFoundException::new); + if (totalGroupMemberCount == 30) { + deleteGroupInvite(memberId, groupId, groupOwnerId); throw new GroupMemberCountLimitException(); } @@ -83,22 +87,23 @@ public GroupAcceptNotificationDto acceptGroupInvite(final Long memberId, final L .orElseThrow(MemberNotFoundException::new); final Group group = groupRepository.findGroupById(groupId) .orElseThrow(GroupNotFoundException::new); - final Long groupOwnerId = memberGroupRepository.findGroupOwnerId(groupId) - .orElseThrow(GroupNotFoundException::new); transactionTemplate.executeWithoutResult(status -> { - final int isDenyRequest = groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( - groupId, groupOwnerId, memberId); - if (isDenyRequest != 1) { - throw new GroupInviteNotFoundException(); - } - + deleteGroupInvite(memberId, groupId, groupOwnerId); memberGroupRepository.save(MemberGroup.createGroupMember(groupMember, group)); }); return new GroupAcceptNotificationDto(groupMember.getNickname(), groupOwnerId); } + private void deleteGroupInvite(final Long memberId, final Long groupId, final Long groupOwnerId) { + final int isDenyRequest = groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, groupOwnerId, memberId); + if (isDenyRequest != 1) { + throw new GroupInviteNotFoundException(); + } + } + /** * 사용자는 사용자가 속한 그룹을 탈퇴한다. *
주의 - 그룹 탈퇴 시 아래 조건에 해당하면 예외가 발생한다. diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java index 3a56a4110..a3306a721 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java @@ -260,6 +260,9 @@ class MemberGroupCommandServiceTest { Long groupId = 1L; given(groupRepository.getTotalGroupMemberCount(groupId)).willReturn(Optional.of(30L)); + given(memberGroupRepository.findGroupOwnerId(groupId)).willReturn(Optional.of(2L)); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, 2L, memberId)).willReturn(1); assertThatThrownBy( () -> groupMemberCommandService.acceptGroupInvite(memberId, groupId))