Skip to content

Commit

Permalink
[HOTFIX] 친구 조회에 본인 제외하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Jan 11, 2024
1 parent f4cb0b9 commit 099769e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@EntityListeners(AuditListener.class)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Friend implements Auditable {

@Id
@GeneratedValue(generator = "uuid2")
@Column(name = "id", columnDefinition = "BINARY(16)")
Expand Down Expand Up @@ -72,4 +73,15 @@ private void validate(final Member fromMember, final Member toMember) {
public void updateStatus(final FriendStatus friendStatus) {
this.friendStatus = friendStatus;
}

public Member getFriendMember(final Member loginMember) {
if (isFromMember(loginMember)) {
return this.toMember;
}
return this.fromMember;
}

private boolean isFromMember(final Member member) {
return this.fromMember.getId().equals(member.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public interface FriendMapper {
Friend toEntity(Member fromMember, Member toMember);

@IterableMapping(elementTargetType = FriendResponse.class)
List<FriendResponse> toResponses(List<Friend> friends);
List<FriendResponse> toResponses(List<Member> friends);

@Mapping(target = "memberId", source = "fromMember.id")
@Mapping(target = "nickname", source = "fromMember.nickname")
@Mapping(target = "profileImage", source = "fromMember.profileImage")
FriendResponse toResponse(Friend friend);
@Mapping(target = "memberId", source = "id")
@Mapping(target = "nickname", source = "nickname")
@Mapping(target = "profileImage", source = "profileImage")
FriendResponse toResponse(Member member);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.twtw.backend.domain.friend.repository;

import static com.twtw.backend.domain.friend.entity.QFriend.friend;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.twtw.backend.domain.friend.entity.Friend;
import com.twtw.backend.domain.friend.entity.FriendStatus;
import com.twtw.backend.domain.member.entity.Member;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static com.twtw.backend.domain.friend.entity.QFriend.friend;

@Repository
@RequiredArgsConstructor
public class FriendQueryRepositoryImpl implements FriendQueryRepository {
Expand Down Expand Up @@ -70,12 +68,12 @@ public List<Friend> findByMemberAndMemberNickname(final Member member, final Str
.and(
friend.toMember
.eq(member)
.and(friend.fromMember.nickname.eq(nickname))
.and(friend.fromMember.nickname.containsIgnoreCase(nickname))
.or(
friend.fromMember
.eq(member)
.and(
friend.toMember.nickname.eq(
friend.toMember.nickname.containsIgnoreCase(
nickname)))))
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,30 @@ private Friend getFriendById(final UUID loginMemberId, final UUID memberId) {
@Transactional(readOnly = true)
public List<FriendResponse> getFriends() {
final Member loginMember = authService.getMemberByJwt();
final List<Friend> friends = friendRepository.findByMember(loginMember);
final List<Member> friends = friendRepository.findByMember(loginMember).stream()
.map(friend -> friend.getFriendMember(loginMember))
.toList();
return friendMapper.toResponses(friends);
}

@Transactional(readOnly = true)
public List<FriendResponse> getFriendsByStatus(final FriendStatus friendStatus) {
final Member loginMember = authService.getMemberByJwt();
final List<Friend> friends =
friendRepository.findByMemberAndFriendStatus(loginMember, friendStatus);
final List<Member> friends =
friendRepository.findByMemberAndFriendStatus(loginMember, friendStatus).stream()
.map(friend -> friend.getFriendMember(loginMember))
.toList();
return friendMapper.toResponses(friends);
}

@Transactional(readOnly = true)
public List<FriendResponse> getFriendByNickname(final String nickname) {
final Member loginMember = authService.getMemberByJwt();
final List<Friend> friends =
friendRepository.findByMemberAndMemberNickname(loginMember, nickname);
final List<Member> friends =
friendRepository.findByMemberAndMemberNickname(loginMember, nickname)
.stream()
.map(friend -> friend.getFriendMember(loginMember))
.toList();
return friendMapper.toResponses(friends);
}
}

0 comments on commit 099769e

Please sign in to comment.