Skip to content

Commit

Permalink
fix : 그룹 요약 조회 그룹 아이디 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-1116 committed Jun 17, 2024
1 parent e33d2fd commit 0146df3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ ResponseEntity<ApiSpec<GroupCapsuleDetailResponse>> getGroupCapsuleDetailByCapsu
ResponseEntity<ApiSpec<GroupCapsuleSummaryResponse>> getGroupCapsuleSummaryByCapsuleId(
Long memberId,

@Parameter(in = ParameterIn.QUERY, description = "그룹 아이디", required = true)
Long groupId,

@Parameter(in = ParameterIn.PATH, description = "조회할 캡슐 아이디", required = true)
Long capsuleId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ public ResponseEntity<ApiSpec<GroupCapsuleDetailResponse>> getGroupCapsuleDetail
@Override
public ResponseEntity<ApiSpec<GroupCapsuleSummaryResponse>> getGroupCapsuleSummaryByCapsuleId(
@AuthenticationPrincipal Long memberId,
@RequestParam("group_id") Long groupId,
@PathVariable("capsule_id") Long capsuleId
) {
CombinedGroupCapsuleSummaryDto groupCapsuleSummary = groupCapsuleService.findGroupCapsuleSummary(
memberId,
groupId,
capsuleId
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private StringExpression groupConcatDistinct(final StringExpression expression)
}

public Optional<GroupCapsuleSummaryDto> findGroupCapsuleSummaryDtoByCapsuleId(
final Long groupId,
final Long capsuleId
) {
return Optional.ofNullable(
Expand Down Expand Up @@ -120,7 +119,6 @@ public Optional<GroupCapsuleSummaryDto> findGroupCapsuleSummaryDtoByCapsuleId(
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.group, group)
.where(capsule.id.eq(capsuleId)
.and(capsule.group.id.eq(groupId))
.and(capsule.type.eq(CapsuleType.GROUP))
)
.fetchOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,25 @@ private boolean capsuleNotOpened(final GroupCapsuleDetailDto detailDto) {
* 그룹 캡슐의 요약 정보를 조회한다.
* <br>
* @param memberId 사용자 아이디
* @param groupId 캡슐이 만들어진 그룹 아이디
* @param capsuleId 조회할 캡슐 아이디
* @return 그룹 캡슐의 요약 정보(캡슐, 그룹원)
* @throws NoGroupAuthorityException 그룹에 대한 권한이 존재하지 않으면 예외가 발생한다.
*/
public CombinedGroupCapsuleSummaryDto findGroupCapsuleSummary(
final Long memberId,
final Long groupId,
final Long capsuleId
) {
GroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId)
.orElseThrow(CapsuleNotFondException::new);

List<GroupCapsuleMemberDto> groupCapsuleMembers = memberGroupRepository.findGroupCapsuleMembers(
groupId, capsuleId);
groupCapsuleSummaryDto.groupId(), capsuleId);

GroupCapsuleMemberDto requestMember = groupCapsuleMembers.stream()
.filter(dto -> memberId.equals(dto.id()))
.findAny()
.orElseThrow(NoGroupAuthorityException::new);

GroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(
groupId, capsuleId)
.orElseThrow(CapsuleNotFondException::new);

Boolean hasEditPermission = requestMember.id().equals(groupCapsuleSummaryDto.creatorId());
Boolean hasDeletePermission = hasEditPermission || requestMember.isGroupOwner();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void setup(@Autowired EntityManager entityManager) {
// given
//when
GroupCapsuleSummaryDto capsuleSummaryDto = groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(
groupId, capsule.getId()).orElseThrow();
capsule.getId()).orElseThrow();

//then
assertSoftly(
Expand All @@ -165,7 +165,7 @@ void setup(@Autowired EntityManager entityManager) {

//when
Optional<GroupCapsuleSummaryDto> detailDto = groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(
notCapsuleId, groupId);
notCapsuleId);
//then
assertThat(detailDto).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,31 +460,30 @@ class GroupCapsuleServiceTest {
//given
Long groupId = 1L;
Long notGroupMemberId = 999L;
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));
given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(0, 10, false));

//when
//then
assertThatThrownBy(
() -> groupCapsuleService.findGroupCapsuleSummary(notGroupMemberId, groupId, capsuleId))
() -> groupCapsuleService.findGroupCapsuleSummary(notGroupMemberId, capsuleId))
.isInstanceOf(NoGroupAuthorityException.class)
.hasMessageContaining(ErrorCode.NO_GROUP_AUTHORITY_ERROR.getMessage());
}

@Test
void 그룹원이_없는_그룹_캡슐을_요약_조회_시_예외가_발생한다() {
void 그룹원이_존재하지_않는_그룹_캡슐을_요약_조회_시_예외가_발생한다() {
//given
Long groupId = 1L;

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(0, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.empty());

//when
//then
assertThatThrownBy(
() -> groupCapsuleService.findGroupCapsuleSummary(memberId, groupId, capsuleId))
() -> groupCapsuleService.findGroupCapsuleSummary(memberId, capsuleId))
.isInstanceOf(CapsuleNotFondException.class)
.hasMessageContaining(ErrorCode.CAPSULE_NOT_FOUND_ERROR.getMessage());
}
Expand All @@ -496,13 +495,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(0, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
memberId, groupId, capsuleId);;
memberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto).isNotNull();
Expand All @@ -516,13 +515,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(1, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
groupMemberId, groupId, capsuleId);;
groupMemberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto.hasEditPermission()).isFalse();
Expand All @@ -536,13 +535,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(1, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
groupMemberId, groupId, capsuleId);;
groupMemberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto.hasDeletePermission()).isFalse();
Expand All @@ -555,13 +554,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(1, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
memberId, groupId, capsuleId);;
memberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto.hasEditPermission()).isTrue();
Expand All @@ -574,13 +573,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(1, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
memberId, groupId, capsuleId);;
memberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto.hasDeletePermission()).isTrue();
Expand All @@ -593,13 +592,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(1, 10, true));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
memberId, groupId, capsuleId);;
memberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto.isRequestMemberCapsuleOpen()).isTrue();
Expand All @@ -612,13 +611,13 @@ class GroupCapsuleServiceTest {

given(memberGroupRepository.findGroupCapsuleMembers(anyLong(), anyLong()))
.willReturn(GroupCapsuleMemberDtoFixture.members(1, 10, false));
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(groupId, capsuleId))
given(groupCapsuleQueryRepository.findGroupCapsuleSummaryDtoByCapsuleId(capsuleId))
.willReturn(Optional.of(
GroupCapsuleSummaryDtoFixture.groupCapsule(groupId, memberId)));

//when
CombinedGroupCapsuleSummaryDto groupCapsuleSummaryDto = groupCapsuleService.findGroupCapsuleSummary(
memberId, groupId, capsuleId);;
memberId, capsuleId);;

//then
assertThat(groupCapsuleSummaryDto.isRequestMemberCapsuleOpen()).isFalse();
Expand Down

0 comments on commit 0146df3

Please sign in to comment.