11package team .wego .wegobackend .user .application ;
22
3+ import java .util .ArrayList ;
4+ import java .util .HashSet ;
35import java .util .List ;
6+ import java .util .Set ;
47import lombok .RequiredArgsConstructor ;
58import lombok .extern .slf4j .Slf4j ;
69import org .springframework .context .ApplicationEventPublisher ;
710import org .springframework .stereotype .Service ;
811import org .springframework .transaction .annotation .Transactional ;
9- import team .wego .wegobackend .notification .application .SseEmitterService ;
10- import team .wego .wegobackend .notification .application .dto .NotificationType ;
11- import team .wego .wegobackend .notification .application .dto .response .NotificationResponse ;
12- import team .wego .wegobackend .notification .domain .Notification ;
13- import team .wego .wegobackend .notification .repository .NotificationRepository ;
1412import team .wego .wegobackend .user .application .dto .response .FollowListResponse ;
1513import team .wego .wegobackend .user .application .dto .response .FollowResponse ;
14+ import team .wego .wegobackend .user .application .dto .response .FollowerListResponse ;
15+ import team .wego .wegobackend .user .application .dto .response .WrapperFollowerResponse ;
1616import team .wego .wegobackend .user .application .event .FollowEvent ;
1717import team .wego .wegobackend .user .domain .Follow ;
1818import team .wego .wegobackend .user .domain .User ;
@@ -34,10 +34,6 @@ public class FollowService {
3434
3535 private final UserRepository userRepository ;
3636
37- private final NotificationRepository notificationRepository ;
38-
39- private final SseEmitterService sseEmitterService ;
40-
4137 private final ApplicationEventPublisher eventPublisher ;
4238
4339 public void follow (String followNickname , Long followerId ) {
@@ -101,4 +97,30 @@ public FollowListResponse followList(Long userId, Long cursor, Integer size) {
10197
10298 return new FollowListResponse (list , nextCursor );
10399 }
100+
101+ @ Transactional (readOnly = true )
102+ public FollowerListResponse followerList (Long userId , Long cursor , Integer size ) {
103+
104+ if (!userRepository .existsById (userId )) {
105+ throw new UserNotFoundException ();
106+ }
107+
108+ List <FollowResponse > list = followRepository .findFollowerList (userId , cursor , size );
109+
110+ // 맞팔로우 여부 조회: 내가 팔로우한 사람들의 ID 조회
111+ Set <Long > followingUserIds = followRepository .findFolloweeIdsByFollowerId (userId );
112+
113+ List <WrapperFollowerResponse > result = new ArrayList <>();
114+
115+ for (FollowResponse follower : list ) {
116+ boolean isFollow = followingUserIds .contains (follower .getUserId ());
117+ follower .getUserId (), follower .getNickname (), isFollow );
118+ WrapperFollowerResponse response = new WrapperFollowerResponse (follower , isFollow );
119+ result .add (response );
120+ }
121+
122+ Long nextCursor = list .isEmpty () ? null : list .getLast ().getFollowId ();
123+
124+ return new FollowerListResponse (result , nextCursor );
125+ }
104126}
0 commit comments