diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApi.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApi.java index be38b0b37..7f79e682a 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApi.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApi.java @@ -126,6 +126,8 @@ ResponseEntity deleteGroupMember( ResponseEntity> rejectGroupInvitation( Long memberId, + Long groupId, + @Parameter(in = ParameterIn.PATH, description = "그룹 초대 대상 아이디", required = true) Long groupOwnerId ); diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApiController.java index d0eb7feeb..3efb49539 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/api/GroupApiController.java @@ -82,12 +82,13 @@ public ResponseEntity deleteGroupMember(Long groupId, Long memberId) { return null; } - @DeleteMapping(value = "/reject/{target_id}") + @DeleteMapping(value = "/reject/{group_id}/member/{target_id}") public ResponseEntity> rejectGroupInvitation( @AuthenticationPrincipal final Long memberId, + @PathVariable("group_id") final Long groupId, @PathVariable("target_id") final Long targetId) { - groupService.rejectRequestGroup(memberId, targetId); + groupService.rejectRequestGroup(memberId, groupId, targetId); return ResponseEntity.ok( ApiSpec.empty( diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/entity/GroupInvite.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/entity/GroupInvite.java index 434e245ba..690014c01 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/entity/GroupInvite.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/entity/GroupInvite.java @@ -26,6 +26,9 @@ public class GroupInvite extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "group_id", nullable = false) + private Long groupId; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "group_owner_id", nullable = false) private Member groupOwner; @@ -34,13 +37,14 @@ public class GroupInvite extends BaseEntity { @JoinColumn(name = "group_member_id", nullable = false) private Member groupMember; - private GroupInvite(Member groupOwner, Member groupMember) { + private GroupInvite(Long groupId, Member groupOwner, Member groupMember) { + this.groupId = groupId; this.groupOwner = groupOwner; this.groupMember = groupMember; } - public static GroupInvite createOf(Member groupOwner, Member groupMember) { - return new GroupInvite(groupOwner, groupMember); + public static GroupInvite createOf(Long groupId, Member groupOwner, Member groupMember) { + return new GroupInvite(groupId, groupOwner, groupMember); } } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/groupInviteRepository/GroupInviteRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/groupInviteRepository/GroupInviteRepository.java index e18663d1a..1331805dd 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/groupInviteRepository/GroupInviteRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/groupInviteRepository/GroupInviteRepository.java @@ -8,6 +8,7 @@ public interface GroupInviteRepository extends Repository, void save(GroupInvite groupInvite); - int deleteGroupInviteByGroupOwnerIdAndGroupMemberId(Long groupOwnerId, Long groupMemberId); + int deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId(Long groupId, Long groupOwnerId, + Long groupMemberId); } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupServiceImpl.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupServiceImpl.java index efba68fbc..b1252d0ea 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupServiceImpl.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/GroupServiceImpl.java @@ -48,8 +48,9 @@ public void inviteGroup(final Long memberId, final Long groupId, final Long targ } @Override - public void rejectRequestGroup(final Long groupMemberId, final Long targetId) { - groupWriteService.rejectRequestGroup(groupMemberId, targetId); + public void rejectRequestGroup(final Long groupMemberId, final Long groupId, + final Long targetId) { + groupWriteService.rejectRequestGroup(groupMemberId, groupId, targetId); } @Override diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteService.java index 88db72623..6eb08e6f6 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteService.java @@ -8,7 +8,7 @@ public interface GroupWriteService { void inviteGroup(final Long memberId, final Long groupId, final Long targetId); - void rejectRequestGroup(final Long memberId, final Long targetId); + void rejectRequestGroup(final Long memberId, final Long groupId, final Long targetId); void acceptGroupInvite(final Long memberId, final Long groupId, final Long targetId); diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteServiceImpl.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteServiceImpl.java index e2198c721..b2065bee5 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteServiceImpl.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/write/GroupWriteServiceImpl.java @@ -62,7 +62,7 @@ public void inviteGroup(final Long memberId, final Long groupId, final Long targ final Member groupMember = memberRepository.findMemberById(targetId).orElseThrow( MemberNotFoundException::new); - final GroupInvite groupInvite = GroupInvite.createOf(groupOwner, groupMember); + final GroupInvite groupInvite = GroupInvite.createOf(groupId, groupOwner, groupMember); final GroupOwnerSummaryDto[] summaryDto = new GroupOwnerSummaryDto[1]; @@ -85,9 +85,9 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } @Transactional - public void rejectRequestGroup(final Long memberId, final Long targetId) { - final int isDenyRequest = groupInviteRepository.deleteGroupInviteByGroupOwnerIdAndGroupMemberId( - targetId, memberId); + public void rejectRequestGroup(final Long memberId, final Long groupId, final Long targetId) { + final int isDenyRequest = groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId); if (isDenyRequest != 1) { throw new GroupInviteNotFoundException(); @@ -103,8 +103,8 @@ public void acceptGroupInvite(final Long memberId, final Long groupId, final Lon transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { - final int isDenyRequest = groupInviteRepository.deleteGroupInviteByGroupOwnerIdAndGroupMemberId( - targetId, memberId); + final int isDenyRequest = groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId); if (isDenyRequest != 1) { throw new GroupInviteNotFoundException(); diff --git a/backend/core/src/main/resources/db/migration/V26__group_invite_add.sql b/backend/core/src/main/resources/db/migration/V26__group_invite_add.sql new file mode 100644 index 000000000..61254b875 --- /dev/null +++ b/backend/core/src/main/resources/db/migration/V26__group_invite_add.sql @@ -0,0 +1,3 @@ +alter table group_invite add column group_id BIGINT; +ALTER TABLE group_invite + ADD CONSTRAINT fk_group_invite_group_id FOREIGN KEY (group_id) REFERENCES `group` (group_id); \ No newline at end of file diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java index 8af8a3acb..e3b158f37 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java @@ -157,14 +157,15 @@ class GroupWriteServiceTest { void 그룹원은_그룹초대_삭제에서_1을_반환하면_거부할_수_있다() { //given Long memberId = 1L; + Long groupId = 1L; Long targetId = 2L; - given(groupInviteRepository.deleteGroupInviteByGroupOwnerIdAndGroupMemberId( - targetId, memberId)).willReturn(1); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(1); //when // then - assertThatCode(() -> groupWriteService.rejectRequestGroup(memberId, targetId)) + assertThatCode(() -> groupWriteService.rejectRequestGroup(memberId, groupId, targetId)) .doesNotThrowAnyException(); } @@ -172,14 +173,15 @@ class GroupWriteServiceTest { void 그룹원은_그룹초대_삭제에서_0을_반환하면_거부가_실패_한다() { //given Long memberId = 1L; + Long groupId = 1L; Long targetId = 2L; - given(groupInviteRepository.deleteGroupInviteByGroupOwnerIdAndGroupMemberId( - targetId, memberId)).willReturn(0); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(0); //when // then - assertThatThrownBy(() -> groupWriteService.rejectRequestGroup(memberId, targetId)) + assertThatThrownBy(() -> groupWriteService.rejectRequestGroup(memberId, groupId, targetId)) .isInstanceOf(GroupInviteNotFoundException.class) .hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage()); } @@ -195,8 +197,8 @@ class GroupWriteServiceTest { given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupMember)); given(groupRepository.findGroupById(groupId)).willReturn( Optional.of(GroupFixture.group())); - given(groupInviteRepository.deleteGroupInviteByGroupOwnerIdAndGroupMemberId( - targetId, memberId)).willReturn(1); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(1); //when groupWriteService.acceptGroupInvite(memberId, groupId, targetId); @@ -216,8 +218,8 @@ class GroupWriteServiceTest { given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupMember)); given(groupRepository.findGroupById(groupId)).willReturn( Optional.of(GroupFixture.group())); - given(groupInviteRepository.deleteGroupInviteByGroupOwnerIdAndGroupMemberId( - targetId, memberId)).willReturn(0); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(0); //when //then