Skip to content

Commit

Permalink
refact : 그룹 초대에 그룹 id 추가
Browse files Browse the repository at this point in the history
- 기존의 그룹 owner와 그룹 member로는 식별 안됨
  • Loading branch information
GaBaljaintheroom committed May 13, 2024
1 parent 02a1ff0 commit c3f7609
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ ResponseEntity<Void> deleteGroupMember(
ResponseEntity<ApiSpec<String>> rejectGroupInvitation(
Long memberId,

Long groupId,

@Parameter(in = ParameterIn.PATH, description = "그룹 초대 대상 아이디", required = true)
Long groupOwnerId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ public ResponseEntity<Void> deleteGroupMember(Long groupId, Long memberId) {
return null;
}

@DeleteMapping(value = "/reject/{target_id}")
@DeleteMapping(value = "/reject/{group_id}/member/{target_id}")
public ResponseEntity<ApiSpec<String>> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface GroupInviteRepository extends Repository<GroupInvite, Long>,

void save(GroupInvite groupInvite);

int deleteGroupInviteByGroupOwnerIdAndGroupMemberId(Long groupOwnerId, Long groupMemberId);
int deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId(Long groupId, Long groupOwnerId,
Long groupMemberId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,31 @@ 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();
}

@Test
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());
}
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit c3f7609

Please sign in to comment.