Skip to content

Commit

Permalink
Merge pull request #497 from tukcomCD2024/fix/group_capsule-B-#495
Browse files Browse the repository at this point in the history
fix : 그룹 캡슐 API 수정 #495
  • Loading branch information
seokho-1116 authored Jun 17, 2024
2 parents f3d226e + af72aa1 commit 05805be
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.reqeust.GroupCapsuleUpdateRequest;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleDetailResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleOpenStateResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleMembersResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSliceResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSummaryResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupMemberCapsuleOpenStatusListResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.MyGroupCapsuleSliceResponse;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.error.ErrorResponse;
Expand Down 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 Expand Up @@ -159,9 +156,9 @@ ResponseEntity<ApiSpec<MyGroupCapsuleSliceResponse>> getMyGroupCapsules(
);

@Operation(
summary = "그룹원의 그룹 캡슐 개봉 상태 확인",
summary = "그룹 캡슐에 대한 그룹원 목록 조회",
description = """
그룹원의 그룹 캡슐 개봉 상태를 확인한다.
그룹 캡슐에 대한 그룹원 목록 조회한다.
""",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group capsule"}
Expand All @@ -177,7 +174,7 @@ ResponseEntity<ApiSpec<MyGroupCapsuleSliceResponse>> getMyGroupCapsules(
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
})
ResponseEntity<ApiSpec<GroupMemberCapsuleOpenStatusListResponse>> getGroupCapsuleOpenStatus(
ResponseEntity<ApiSpec<GroupCapsuleMembersResponse>> getGroupCapsuleMembers(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "개봉 상태를 확인할 캡슐 아이디", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.CombinedGroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSliceRequestDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupMemberCapsuleOpenStatusDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.reqeust.GroupCapsuleCreateRequest;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.reqeust.GroupCapsuleUpdateRequest;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleDetailResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleOpenStateResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleMembersResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSliceResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSummaryResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupMemberCapsuleOpenStatusListResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.MyGroupCapsuleSliceResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.facade.GroupCapsuleFacade;
import site.timecapsulearchive.core.domain.capsule.group_capsule.service.GroupCapsuleService;
Expand Down 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 Expand Up @@ -172,18 +170,18 @@ public ResponseEntity<ApiSpec<MyGroupCapsuleSliceResponse>> getMyGroupCapsules(

@GetMapping(value = "/{capsule_id}/open-status", produces = {"application/json"})
@Override
public ResponseEntity<ApiSpec<GroupMemberCapsuleOpenStatusListResponse>> getGroupCapsuleOpenStatus(
public ResponseEntity<ApiSpec<GroupCapsuleMembersResponse>> getGroupCapsuleMembers(
@AuthenticationPrincipal final Long memberId,
@PathVariable("capsule_id") final Long capsuleId,
@RequestParam("group_id") final Long groupId
) {
List<GroupMemberCapsuleOpenStatusDto> groupMemberCapsuleOpenStatus = groupCapsuleService.findGroupMemberCapsuleOpenStatus(
List<GroupCapsuleMemberDto> groupCapsuleMembers = groupCapsuleService.findGroupCapsuleMembers(
memberId, capsuleId, groupId);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
GroupMemberCapsuleOpenStatusListResponse.create(groupMemberCapsuleOpenStatus)
GroupCapsuleMembersResponse.create(groupCapsuleMembers)
)
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package site.timecapsulearchive.core.domain.capsule.group_capsule.data.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberDto;

@Schema(description = "그룹 캡슐의 그룹원들 목록 응답")
public record GroupCapsuleMembersResponse(
@Schema(description = "그룹 캡슐의 그룹원들 목록")
List<GroupCapsuleMemberResponse> groupCapsuleMembers
) {

public static GroupCapsuleMembersResponse create(
final List<GroupCapsuleMemberDto> groupCapsuleMembers
) {
List<GroupCapsuleMemberResponse> groupCapsuleMemberResponses = groupCapsuleMembers.stream()
.map(GroupCapsuleMemberDto::toResponse)
.toList();

return new GroupCapsuleMembersResponse(groupCapsuleMemberResponses);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static site.timecapsulearchive.core.domain.capsule.entity.QGroupCapsuleOpen.groupCapsuleOpen;
import static site.timecapsulearchive.core.domain.member.entity.QMember.member;
import static site.timecapsulearchive.core.domain.member_group.entity.QMemberGroup.memberGroup;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -16,8 +17,7 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import site.timecapsulearchive.core.domain.capsule.entity.Capsule;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupMemberCapsuleOpenStatusDto;
import site.timecapsulearchive.core.domain.member.entity.QMember;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberDto;

@Repository
@RequiredArgsConstructor
Expand Down Expand Up @@ -59,24 +59,27 @@ public int getBatchSize() {
);
}

public List<GroupMemberCapsuleOpenStatusDto> findGroupMemberCapsuleOpenStatus(
public List<GroupCapsuleMemberDto> findGroupCapsuleMembers(
final Long capsuleId,
final Long groupId
) {
return jpaQueryFactory
.select(
Projections.constructor(
GroupMemberCapsuleOpenStatusDto.class,
groupCapsuleOpen.member.id,
groupCapsuleOpen.member.nickname,
groupCapsuleOpen.member.profileUrl,
GroupCapsuleMemberDto.class,
member.id,
member.nickname,
member.profileUrl,
memberGroup.isOwner,
groupCapsuleOpen.isOpened
)
)
.from(groupCapsuleOpen)
.join(memberGroup).on(groupCapsuleOpen.member.id.eq(memberGroup.member.id))
.join(groupCapsuleOpen.member, member)
.where(groupCapsuleOpen.group.id.eq(groupId)
.and(groupCapsuleOpen.capsule.id.eq(capsuleId))
.and(memberGroup.group.id.eq(groupId))
)
.fetch();
}
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 @@ -20,7 +20,6 @@
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSliceRequestDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupMemberCapsuleOpenStatusDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleOpenQueryRepository;
import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleQueryRepository;
import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin;
Expand Down Expand Up @@ -82,28 +81,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 Expand Up @@ -177,14 +173,21 @@ private void checkGroupAuthority(Long memberId, Long groupId) {
}
}

public List<GroupMemberCapsuleOpenStatusDto> findGroupMemberCapsuleOpenStatus(
public List<GroupCapsuleMemberDto> findGroupCapsuleMembers(
final Long memberId,
final Long capsuleId,
final Long groupId
) {
checkGroupAuthority(memberId, groupId);
List<GroupCapsuleMemberDto> groupCapsuleMembers = groupCapsuleOpenQueryRepository.findGroupCapsuleMembers(
capsuleId, groupId);

boolean isGroupMember = groupCapsuleMembers.stream()
.anyMatch(groupCapsuleMember -> groupCapsuleMember.id().equals(memberId));
if (!isGroupMember) {
throw new NoGroupAuthorityException();
}

return groupCapsuleOpenQueryRepository.findGroupMemberCapsuleOpenStatus(capsuleId, groupId);
return groupCapsuleMembers;
}
}

This file was deleted.

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
Loading

0 comments on commit 05805be

Please sign in to comment.