|
6 | 6 | import com.example.cp_main_be.domain.member.user.domain.repository.UserRepository; |
7 | 7 | import com.example.cp_main_be.domain.social.follow.domain.Follow; |
8 | 8 | import com.example.cp_main_be.domain.social.follow.domain.repository.FollowRepository; |
| 9 | +import com.example.cp_main_be.domain.social.follow.dto.FollowResponseDTO; |
9 | 10 | import com.example.cp_main_be.global.exception.UserNotFoundException; |
10 | 11 | import java.util.List; |
11 | 12 | import java.util.stream.Collectors; |
@@ -63,24 +64,42 @@ public void unfollowUser(Long followerId, Long followingId) { |
63 | 64 | } |
64 | 65 |
|
65 | 66 | @Transactional(readOnly = true) |
66 | | - public List<User> getFollowers(Long userId) { |
| 67 | + public List<FollowResponseDTO> getFollowers(Long userId) { |
67 | 68 | User user = |
68 | 69 | userRepository |
69 | 70 | .findById(userId) |
70 | 71 | .orElseThrow(() -> new UserNotFoundException("사용자를 찾을 수 없습니다.")); |
71 | | - return followRepository.findByFollowing(user).stream() |
72 | | - .map(Follow::getFollower) |
73 | | - .collect(Collectors.toList()); |
| 72 | + |
| 73 | + List<User> userList = followRepository.findByFollowing(user).stream() |
| 74 | + .map(Follow::getFollower) |
| 75 | + .toList(); |
| 76 | + |
| 77 | + |
| 78 | + return userList.stream() |
| 79 | + .map(member -> FollowResponseDTO.builder() |
| 80 | + .username(member.getUsername()) |
| 81 | + .userImageUrl(member.getProfileImageUrl()) |
| 82 | + .userId(member.getId()) |
| 83 | + .build()) |
| 84 | + .toList(); |
74 | 85 | } |
75 | 86 |
|
76 | 87 | @Transactional(readOnly = true) |
77 | | - public List<User> getFollowing(Long userId) { |
| 88 | + public List<FollowResponseDTO> getFollowing(Long userId) { |
78 | 89 | User user = |
79 | 90 | userRepository |
80 | 91 | .findById(userId) |
81 | 92 | .orElseThrow(() -> new UserNotFoundException("사용자를 찾을 수 없습니다.")); |
82 | | - return followRepository.findByFollower(user).stream() |
| 93 | + List<User> userList = followRepository.findByFollower(user).stream() |
83 | 94 | .map(Follow::getFollowing) |
84 | | - .collect(Collectors.toList()); |
| 95 | + .toList(); |
| 96 | + |
| 97 | + return userList.stream() |
| 98 | + .map(member -> FollowResponseDTO.builder() |
| 99 | + .username(member.getUsername()) |
| 100 | + .userImageUrl(member.getProfileImageUrl()) |
| 101 | + .userId(member.getId()) |
| 102 | + .build()) |
| 103 | + .toList(); |
85 | 104 | } |
86 | 105 | } |
0 commit comments