Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
vact19 committed Feb 22, 2024
2 parents 9656078 + d00505a commit 8b1eccc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 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 @@ -62,12 +62,13 @@ else if (friendRequest == null && !reqMember.equals(rspMember)) {

// 요청자와 회원 정보가 일치하지 않으면 예외
Member member = friendRequest.getReqMember();
if(member.getId() != reqMember.getId()) {
if(!member.getId().equals(reqMember.getId())) {
throw new IllegalStateException("회원 정보가 일치하지 않습니다.");
}

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

}

// 친구 요청 수락
Expand Down Expand Up @@ -111,7 +112,7 @@ public void rejectFriendRequest(FriendReqDto reqDto, long memberId) {

// 요청 받은 자와 회원 정보가 일치하지 않으면 예외
Member member = friendRequest.getRspMember();
if(member != rspMember) {
if(!member.getId().equals(rspMember.getId())) {
throw new IllegalStateException("회원 정보가 일치하지 않습니다.");
}

Expand All @@ -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 8b1eccc

Please sign in to comment.