TIL(20240624) [아웃소싱 프로젝트: fix 팔로우]
TIL(20240624) [아웃소싱 프로젝트: fix 팔로우]
📌 Spring
💡 아웃소싱 프로젝트: fix 팔로우
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}
This post is licensed under CC BY 4.0 by the author.