diff --git a/src/main/java/com/potatocake/everymoment/service/FriendDiaryService.java b/src/main/java/com/potatocake/everymoment/service/FriendDiaryService.java index 430ae61..0d324a9 100644 --- a/src/main/java/com/potatocake/everymoment/service/FriendDiaryService.java +++ b/src/main/java/com/potatocake/everymoment/service/FriendDiaryService.java @@ -87,6 +87,10 @@ public FriendDiaryResponse getFriendDiary(Long memberId, Long diaryId) { Diary diary = diaryRepository.findById(diaryId) .orElseThrow(() -> new GlobalException(ErrorCode.DIARY_NOT_FOUND)); + if(!diary.isPublic()){ + throw new GlobalException(ErrorCode.DIARY_NOT_PUBLIC); + } + //글쓴사람이 친구인지 확인 Member currentMember = memberRepository.findById(memberId) .orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_FOUND)); diff --git a/src/main/java/com/potatocake/everymoment/service/FriendService.java b/src/main/java/com/potatocake/everymoment/service/FriendService.java index f21dead..852e850 100644 --- a/src/main/java/com/potatocake/everymoment/service/FriendService.java +++ b/src/main/java/com/potatocake/everymoment/service/FriendService.java @@ -22,6 +22,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -49,10 +50,10 @@ public OneFriendDiariesResponse OneFriendDiariesResponse(Long memberid, Long fri friendRepository.findByMemberAndFriend(currentMember, friend) .orElseThrow(() -> new GlobalException(ErrorCode.FRIEND_NOT_FOUND)); - Pageable pageable = PageRequest.of(key, size); + Pageable pageable = PageRequest.of(key, size, Sort.by(Sort.Direction.DESC, "createAt")); Page diaries = diaryRepository.findAll( - DiarySpecification.filterDiaries(null, null, null, date, null, null, null) + FriendDiarySpecification.filterDiaries(null, null, null, date, null, null) .and((root, query, builder) -> builder.equal(root.get("member").get("id"), friendId)), pageable);