Skip to content

Commit

Permalink
Merge pull request #62 from kakao-tech-campus-2nd-step3/fix/61-friend…
Browse files Browse the repository at this point in the history
…-diary-err

fix: 친구 일기 조회 API 에러 수정
  • Loading branch information
peeerr authored Oct 22, 2024
2 parents 1f40cfe + 639bbe9 commit 29f8796
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/potatocake/everymoment/entity/Diary.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.potatocake.everymoment.entity;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down Expand Up @@ -57,7 +56,7 @@ public class Diary extends BaseTimeEntity {
@Builder.Default
private boolean isPublic = false;

@OneToMany(mappedBy = "diary", cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(mappedBy = "diary")
private Set<DiaryCategory> diaryCategories = new HashSet<>();

public void updateContent(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public FriendDiariesResponse getFriendDiaries(Long memberId, DiaryFilterRequest

List<Friend> friends = friendRepository.findFriendsByMember(currentMember);
List<Long> friendIdList = friends.stream()
.map(Friend::getId)
.map(friend -> friend.getFriend().getId())
.collect(Collectors.toList());

Page<Diary> diaryPage;
Expand All @@ -64,7 +64,7 @@ public FriendDiariesResponse getFriendDiaries(Long memberId, DiaryFilterRequest
diaryFilterRequest.getFrom(),
diaryFilterRequest.getUntil(),
diaryFilterRequest.getIsBookmark())
.and((root, query, builder) -> root.get("member").in(friendIdList));
.and((root, query, builder) -> root.get("member").get("id").in(friendIdList));

diaryPage = diaryRepository.findAll(spec,
PageRequest.of(diaryFilterRequest.getKey(), diaryFilterRequest.getSize()));
Expand Down Expand Up @@ -92,10 +92,10 @@ public FriendDiaryResponse getFriendDiary(Long memberId, Long diaryId) {

List<Friend> friends = friendRepository.findFriendsByMember(currentMember);
List<Long> friendIdList = friends.stream()
.map(Friend::getId)
.map(friend -> friend.getFriend().getId())
.collect(Collectors.toList());

if (!friendIdList.contains(diary.getMember())) {
if (!friendIdList.contains(diary.getMember().getId())) {
throw new GlobalException(ErrorCode.FRIEND_NOT_FOUND);
}

Expand Down Expand Up @@ -151,4 +151,5 @@ private FriendDiarySimpleResponse convertToFriendDiariesResponseDTO(Diary savedD
.createAt(savedDiary.getCreateAt())
.build();
}

}

0 comments on commit 29f8796

Please sign in to comment.