Skip to content

Commit

Permalink
Merge pull request #41 from codingBottle/friend
Browse files Browse the repository at this point in the history
[Fix] 친구 조회 문제 해결
  • Loading branch information
Hxxjeong authored Feb 21, 2024
2 parents 7ed449b + dcba6e7 commit d00505a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public RspTemplate<RequestListRspDto> getRequestList(Authentication authenticati
}

// 친구 목록 조회
@GetMapping("{email}")
public RspTemplate<FriendListRspDto> getFriendList(@PathVariable String email) {
List<Friend> friends = friendService.getFriendList(email);
@GetMapping
public RspTemplate<FriendListRspDto> getFriendList(Authentication authentication) {
List<Friend> friends = friendService.getFriendList(Long.parseLong(authentication.getName()));
FriendListRspDto rspDto = FriendListRspDto.from(friends);
return new RspTemplate<>(HttpStatus.OK, "친구 목록", rspDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class Friend extends BaseTimeEntity { // 친구가 된 Entity
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "member1", nullable = false)
private Member member1;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "member2", nullable = false)
private Member member2;

Expand All @@ -33,4 +33,4 @@ public Friend(Member member1, Member member2, FriendshipStatus status) {
this.member2 = member2;
this.status = status;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ else if (friendRequest == null && !reqMember.equals(rspMember)) {

// 친구 요청 저장
friendRequestRepository.save(friendRequest);

}

// 친구 요청 수락
Expand Down Expand Up @@ -130,9 +131,9 @@ public List<FriendRequest> getRequestList(long memberId) {
}

// 친구 목록 조회
public List<Friend> getFriendList(String email) {
public List<Friend> getFriendList(long memberId) {
// 회원이 없는 경우 예외
Member member = memberRepository.findByEmail(email)
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new NoSuchElementException("회원을 찾을 수 없습니다."));

return friendRepository.findFriendsByMember(member);
Expand Down

0 comments on commit d00505a

Please sign in to comment.