Skip to content

Commit

Permalink
fix : 그룹 초대 조회 및 삭제 로직 수정
Browse files Browse the repository at this point in the history
- 기존의 조회해서 권한을 확인하는 대신 조회 시 그룹장 아이디 추가
  • Loading branch information
seokho-1116 committed Jun 6, 2024
1 parent b19ab6e commit 276cc8f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ ResponseEntity<ApiSpec<String>> acceptGroupInvitation(
responseCode = "200",
description = "처리 완료"
),
@ApiResponse(
responseCode = "403",
description = "그룹장이 아닌 경우 예외가 발생한다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "404",
description = "그룹 초대를 찾을 수 없는 경우 발생한다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ private GroupInvite(Group group, Member groupOwner, Member groupMember) {
public static GroupInvite createOf(Group group, Member groupOwner, Member groupMember) {
return new GroupInvite(group, groupOwner, groupMember);
}

public void validateOwner(Long memberId) {
if (!groupOwner.getId().equals(memberId)) {
throw new NoGroupAuthorityException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ int deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId(
@Modifying
void bulkDelete(@Param("groupInviteIds") List<Long> groupInviteIds);

Optional<GroupInvite> findGroupInviteById(Long groupInviteId);
Optional<GroupInvite> findGroupInviteByIdAndGroupOwnerId(Long groupInviteId, Long groupOwnerId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ private void deleteGroupInvite(final Long memberId, final Long groupId,

@Transactional
public void deleteGroupInvite(final Long memberId, final Long groupInviteId) {
final GroupInvite groupInvite = groupInviteRepository.findGroupInviteById(groupInviteId)
final GroupInvite groupInvite = groupInviteRepository.findGroupInviteByIdAndGroupOwnerId(
groupInviteId,
memberId)
.orElseThrow(GroupInviteNotFoundException::new);

groupInvite.validateOwner(memberId);

groupInviteRepository.delete(groupInvite);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,12 @@ class MemberGroupCommandServiceTest {
Long groupOwnerId = 1L;
Long groupMemberId = 2L;
Long groupInviteId = 1L;
given(groupInviteRepository.findGroupInviteById(anyLong())).willReturn(
GroupInviteFixture.groupInvite(GroupFixture.group(),
given(groupInviteRepository.findGroupInviteByIdAndGroupOwnerId(anyLong(),
anyLong()))
.willReturn(GroupInviteFixture.groupInvite(GroupFixture.group(),
MemberFixture.memberWithMemberId(groupOwnerId),
MemberFixture.memberWithMemberId(groupMemberId))
);
);

//when
groupMemberCommandService.deleteGroupInvite(groupOwnerId, groupInviteId);
Expand All @@ -329,35 +330,17 @@ class MemberGroupCommandServiceTest {
//given
Long groupOwnerId = 1L;
Long groupInviteId = 1L;
given(groupInviteRepository.findGroupInviteById(anyLong())).willReturn(Optional.empty());
given(groupInviteRepository.findGroupInviteByIdAndGroupOwnerId(anyLong(),
anyLong())).willReturn(Optional.empty());

//when
//then
assertThatThrownBy(() -> groupMemberCommandService.deleteGroupInvite(groupOwnerId, groupInviteId))
assertThatThrownBy(
() -> groupMemberCommandService.deleteGroupInvite(groupOwnerId, groupInviteId))
.isInstanceOf(GroupInviteNotFoundException.class)
.hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage());
}

@Test
void 그룹장이_아닌_사람이_그룹_초대를_삭제하면_예외가_발생한다() {
//given
Long groupOwnerId = 1L;
Long groupMemberId = 2L;
Long groupInviteId = 1L;
given(groupInviteRepository.findGroupInviteById(anyLong())).willReturn(
GroupInviteFixture.groupInvite(GroupFixture.group(),
MemberFixture.memberWithMemberId(groupOwnerId),
MemberFixture.memberWithMemberId(groupMemberId))
);

//when
//then
assertThatThrownBy(
() -> groupMemberCommandService.deleteGroupInvite(groupMemberId, groupInviteId))
.isInstanceOf(NoGroupAuthorityException.class)
.hasMessageContaining(ErrorCode.NO_GROUP_AUTHORITY_ERROR.getMessage());
}

@Test
void 나_자신을_그룹에서_삭제하려하면_예외가_발생한다() {
//given
Expand Down

0 comments on commit 276cc8f

Please sign in to comment.