diff --git a/src/main/java/com/codingbottle/calendar/domain/friend/controller/FriendController.java b/src/main/java/com/codingbottle/calendar/domain/friend/controller/FriendController.java index f2cde76..dc16ca9 100644 --- a/src/main/java/com/codingbottle/calendar/domain/friend/controller/FriendController.java +++ b/src/main/java/com/codingbottle/calendar/domain/friend/controller/FriendController.java @@ -58,9 +58,9 @@ public RspTemplate getRequestList(Authentication authenticati } // 친구 목록 조회 - @GetMapping("{email}") - public RspTemplate getFriendList(@PathVariable String email) { - List friends = friendService.getFriendList(email); + @GetMapping + public RspTemplate getFriendList(Authentication authentication) { + List friends = friendService.getFriendList(Long.parseLong(authentication.getName())); FriendListRspDto rspDto = FriendListRspDto.from(friends); return new RspTemplate<>(HttpStatus.OK, "친구 목록", rspDto); } diff --git a/src/main/java/com/codingbottle/calendar/domain/friend/entity/Friend.java b/src/main/java/com/codingbottle/calendar/domain/friend/entity/Friend.java index 7dea5a2..0474eb3 100644 --- a/src/main/java/com/codingbottle/calendar/domain/friend/entity/Friend.java +++ b/src/main/java/com/codingbottle/calendar/domain/friend/entity/Friend.java @@ -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; @@ -33,4 +33,4 @@ public Friend(Member member1, Member member2, FriendshipStatus status) { this.member2 = member2; this.status = status; } -} +} \ No newline at end of file diff --git a/src/main/java/com/codingbottle/calendar/domain/friend/service/FriendService.java b/src/main/java/com/codingbottle/calendar/domain/friend/service/FriendService.java index f022146..5f523dd 100644 --- a/src/main/java/com/codingbottle/calendar/domain/friend/service/FriendService.java +++ b/src/main/java/com/codingbottle/calendar/domain/friend/service/FriendService.java @@ -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); + } // 친구 요청 수락 @@ -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("회원 정보가 일치하지 않습니다."); } @@ -130,9 +131,9 @@ public List getRequestList(long memberId) { } // 친구 목록 조회 - public List getFriendList(String email) { + public List getFriendList(long memberId) { // 회원이 없는 경우 예외 - Member member = memberRepository.findByEmail(email) + Member member = memberRepository.findById(memberId) .orElseThrow(() -> new NoSuchElementException("회원을 찾을 수 없습니다.")); return friendRepository.findFriendsByMember(member);