public List<PublicPostResponseDto> getFollowedPosts(User user, int page, int pageSize) {
Pageable pageable = PageRequest.of(page, pageSize);
User currentUser = userService.findByUserSeq(user.getUserSeq());
List<Follow> follows = followRepository.findByFromUser(currentUser);
List<PublicPostResponseDto> publicPostResponseDtos = new ArrayList<>();
for (Follow followerList : follows) {
User followedUser = followerList.getToUser();
Page<PublicPost> publicPosts = postRepository.findByUserOrderByCreatedAtDesc(followedUser, pageable);
if (publicPosts.isEmpty()) {
throw new CustomException(ErrorCode.POST_EMPTY);
}
for(PublicPost publicPost : publicPosts) {
PublicPostResponseDto responseDto = new PublicPostResponseDto(publicPost);
publicPostResponseDtos.add(responseDto);
}
}
return publicPostResponseDtos;
}