Skip to content

Commit

Permalink
fix : 서비스 로직 수정
Browse files Browse the repository at this point in the history
- 친구 관계를 조회하도록 수정
- 조회한 친구 관계를 매핑하도록 수정
  • Loading branch information
seokho-1116 committed Aug 14, 2024
1 parent 700ecb1 commit 3a2252e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package site.timecapsulearchive.core.domain.group.data.dto;

import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.friend.data.dto.FriendRelations;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberWithRelationResponse;

Expand All @@ -19,12 +21,15 @@ public record GroupDetailTotalDto(
public static GroupDetailTotalDto as(
final GroupDetailDto groupDetailDto,
final Long groupCapsuleTotalCount,
final List<Long> friendIds
final FriendRelations friendRelations
) {
final List<GroupMemberWithRelationDto> membersWithRelation = groupDetailDto.members()
.stream()
.map(dto -> dto.toRelationDto(friendIds))
.toList();
List<GroupMemberWithRelationDto> membersWithRelation = Collections.emptyList();
if (friendRelations != null) {
membersWithRelation = groupDetailDto.members()
.stream()
.map(dto -> dto.toRelationDto(friendRelations.getFriendRelation(dto.memberId())))
.toList();
}

return new GroupDetailTotalDto(
groupDetailDto.groupName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package site.timecapsulearchive.core.domain.group.data.dto;

import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.friend.data.dto.FriendRelationDto;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberInfoResponse;

public record GroupMemberDto(
Expand All @@ -12,14 +12,16 @@ public record GroupMemberDto(
Boolean isOwner
) {

public GroupMemberWithRelationDto toRelationDto(final List<Long> friendIds) {
public GroupMemberWithRelationDto toRelationDto(final FriendRelationDto friendRelationDto) {
return GroupMemberWithRelationDto.builder()
.memberId(memberId)
.profileUrl(profileUrl)
.nickname(nickname)
.tag(tag)
.isOwner(isOwner)
.isFriend(friendIds.contains(memberId))
.isFriend(friendRelationDto.isFriend())
.isFriendInviteToFriend(friendRelationDto.isFriendInviteToFriend())
.isFriendInviteToMe(friendRelationDto.isFriendInviteToMe())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public record GroupMemberWithRelationDto(
String nickname,
String tag,
Boolean isOwner,
Boolean isFriend
Boolean isFriend,
Boolean isFriendInviteToFriend,
Boolean isFriendInviteToMe
) {

public GroupMemberWithRelationResponse toResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Slice<GroupSummaryDto> findGroupSummaries(

List<Long> getTotalGroupMemberCount(final List<Long> groupIds);

Optional<GroupDetailDto> findGroupDetailByGroupIdAndMemberId(final Long groupId,
Optional<GroupDetailDto> findGroupDetailByGroupIdAndMemberIdExcludeMemberId(final Long groupId,
final Long memberId);

Optional<Long> getTotalGroupMemberCount(Long groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public List<Long> getTotalGroupMemberCount(final List<Long> groupIds) {
* @return 그룹의 상세정보({@code memberId} 제외 그룹원)
*/
@Override
public Optional<GroupDetailDto> findGroupDetailByGroupIdAndMemberId(final Long groupId,
public Optional<GroupDetailDto> findGroupDetailByGroupIdAndMemberIdExcludeMemberId(final Long groupId,
final Long memberId) {
GroupDetailDto groupDetailDtoIncludeMe =
jpaQueryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleQueryRepository;
import site.timecapsulearchive.core.domain.friend.data.dto.FriendRelations;
import site.timecapsulearchive.core.domain.friend.repository.member_friend.MemberFriendRepository;
import site.timecapsulearchive.core.domain.group.data.dto.CompleteGroupSummaryDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto;
Expand Down Expand Up @@ -62,17 +63,21 @@ public Slice<CompleteGroupSummaryDto> findGroupsSlice(
}

public GroupDetailTotalDto findGroupDetailByGroupId(final Long memberId, final Long groupId) {
final GroupDetailDto groupDetailDto = groupRepository.findGroupDetailByGroupIdAndMemberId(
final GroupDetailDto groupDetailDto = groupRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, memberId).orElseThrow(GroupNotFoundException::new);

final Long groupCapsuleCount = groupCapsuleQueryRepository.findGroupCapsuleCount(groupId);

final List<Long> groupMemberIds = groupDetailDto.members().stream()
.map(GroupMemberDto::memberId)
.toList();
final List<Long> friendIds = memberFriendRepository.findFriendIds(groupMemberIds, memberId);

return GroupDetailTotalDto.as(groupDetailDto, groupCapsuleCount, friendIds);
FriendRelations friendRelations = null;
if (!groupMemberIds.isEmpty()) {
friendRelations = memberFriendRepository.findFriendRelations(groupMemberIds, memberId);
}

return GroupDetailTotalDto.as(groupDetailDto, groupCapsuleCount, friendRelations);
}

public List<Group> findAllOwnerGroupsByMemberId(Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void setup(@Autowired EntityManager entityManager) {
void 그룹_아이디와_멤버_아이디로_그룹을_조회하면_그룹_상세가_반환된다() {
//given
//when
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, ownerId).orElseThrow();

//then
Expand All @@ -166,7 +166,7 @@ void setup(@Autowired EntityManager entityManager) {
void 그룹_아이디와_멤버_아이디로_그룹을_조회하면_그룹_정보를_볼_수_있다() {
//given
//when
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, ownerId).orElseThrow();

//then
Expand All @@ -183,7 +183,7 @@ void setup(@Autowired EntityManager entityManager) {
void 그룹_아이디와_멤버_아이디_그룹을_조회하면_그룹원들의_정보를_볼_수_있다() {
//given
//when
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, groupMemberId).orElseThrow();

//then
Expand All @@ -203,7 +203,7 @@ void setup(@Autowired EntityManager entityManager) {
void 그룹_아이디와_멤버_아이디로_그룹을_조회하면_본인은_포함되어_조회되지_않는다() {
//given
//when
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
GroupDetailDto groupDetail = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, groupMemberId).orElseThrow();

List<GroupMemberDto> groupMemberDtos = groupDetail.members();
Expand All @@ -219,7 +219,7 @@ void setup(@Autowired EntityManager entityManager) {
void 그룹_아이디로_그룹을_상세정보를_조회하면_사용자를_제외한_그룹원의_정보를_볼_수_있다() {
//given
//when
GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, ownerId)
.orElseThrow();

Expand All @@ -233,30 +233,18 @@ void setup(@Autowired EntityManager entityManager) {
Long notExistGroupId = 999L;

//when
Optional<GroupDetailDto> groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
Optional<GroupDetailDto> groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
notExistGroupId, ownerId);

//then
assertThat(groupDetailDto).isEmpty();
}

@Test
void 그룹장이_그룹을_상세정보를_조회하면_그룹의_수정권한을_가진다() {
//given
//when
GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
groupId, ownerId)
.orElseThrow();

//then
assertThat(groupDetailDto.isOwner()).isTrue();
}

@Test
void 그룹원이_그룹을_상세정보를_조회하면_그룹의_수정권한이_없다() {
//given
//when
GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberId(
GroupDetailDto groupDetailDto = groupQueryRepository.findGroupDetailByGroupIdAndMemberIdExcludeMemberId(
groupId, groupMemberId)
.orElseThrow();

Expand Down

0 comments on commit 3a2252e

Please sign in to comment.