From 1aa32fbdea461868777dc4eb8460313e38aa9f62 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Mon, 3 Jun 2024 16:58:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EA=B7=B8=EB=A3=B9=20=EC=B4=88?= =?UTF-8?q?=EB=8C=80=20=EC=9D=B8=EC=9B=90=20=EC=B4=88=EA=B3=BC=EC=8B=9C=20?= =?UTF-8?q?=EA=B7=B8=EB=A3=B9=20=EC=B4=88=EB=8C=80=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupInviteRepository.java | 13 ++++++++++-- .../service/MemberGroupCommandService.java | 21 ++++++++++++------- .../MemberGroupCommandServiceTest.java | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-) 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))