diff --git a/src/main/java/konkuk/thip/user/adapter/in/web/UserQueryController.java b/src/main/java/konkuk/thip/user/adapter/in/web/UserQueryController.java index 064de4543..28398ca45 100644 --- a/src/main/java/konkuk/thip/user/adapter/in/web/UserQueryController.java +++ b/src/main/java/konkuk/thip/user/adapter/in/web/UserQueryController.java @@ -99,6 +99,7 @@ public BaseResponse showMyFollowing( return BaseResponse.ok(userGetFollowUsecase.getMyFollowing(userId, cursor, size)); } + @Deprecated @Operation( summary = "팔로잉 여부 조회", description = "특정 사용자가 다른 사용자를 팔로우하고 있는지 확인합니다." diff --git a/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowersResponse.java b/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowersResponse.java index 9326a3a56..3ef9c4fdf 100644 --- a/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowersResponse.java +++ b/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowersResponse.java @@ -7,6 +7,7 @@ @Builder public record UserFollowersResponse( List followers, + Integer totalFollowerCount, String nextCursor, boolean isLast ) { diff --git a/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowingResponse.java b/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowingResponse.java index c558984b4..14e878b01 100644 --- a/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowingResponse.java +++ b/src/main/java/konkuk/thip/user/adapter/in/web/response/UserFollowingResponse.java @@ -7,6 +7,7 @@ @Builder public record UserFollowingResponse( List followings, + Integer totalFollowingCount, String nextCursor, boolean isLast ) { @@ -16,7 +17,8 @@ public record FollowingDto( String nickname, String profileImageUrl, String aliasName, - String aliasColor + String aliasColor, + boolean isFollowing ){ } diff --git a/src/main/java/konkuk/thip/user/adapter/out/persistence/FollowingQueryPersistenceAdapter.java b/src/main/java/konkuk/thip/user/adapter/out/persistence/FollowingQueryPersistenceAdapter.java index f71ce3250..06144ca70 100644 --- a/src/main/java/konkuk/thip/user/adapter/out/persistence/FollowingQueryPersistenceAdapter.java +++ b/src/main/java/konkuk/thip/user/adapter/out/persistence/FollowingQueryPersistenceAdapter.java @@ -48,6 +48,11 @@ public List getLatestFollowerImageUrls(Long userId, int size) { @Override public boolean isFollowingUser(Long userId, Long targetUserId) { - return followingJpaRepository.existsByUserJpaEntity_UserIdAndFollowingUserJpaEntity_UserId(userId, targetUserId); + return followingJpaRepository.existsByUserIdAndFollowingUserId(userId, targetUserId); + } + + @Override + public int getFollowingCountByUser(Long userId) { + return followingJpaRepository.countFollowingByUserId(userId); } } diff --git a/src/main/java/konkuk/thip/user/adapter/out/persistence/repository/following/FollowingJpaRepository.java b/src/main/java/konkuk/thip/user/adapter/out/persistence/repository/following/FollowingJpaRepository.java index 72347b977..0ceae15ab 100644 --- a/src/main/java/konkuk/thip/user/adapter/out/persistence/repository/following/FollowingJpaRepository.java +++ b/src/main/java/konkuk/thip/user/adapter/out/persistence/repository/following/FollowingJpaRepository.java @@ -2,10 +2,15 @@ import konkuk.thip.user.adapter.out.jpa.FollowingJpaEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface FollowingJpaRepository extends JpaRepository, FollowingQueryRepository { - boolean existsByUserJpaEntity_UserIdAndFollowingUserJpaEntity_UserId(Long userId, Long followingUserId); + @Query("SELECT COUNT(f) > 0 FROM FollowingJpaEntity f WHERE f.userJpaEntity.userId = :userId AND f.followingUserJpaEntity.userId = :followingUserId") + boolean existsByUserIdAndFollowingUserId(Long userId, Long followingUserId); + + @Query("SELECT COUNT(f) FROM FollowingJpaEntity f WHERE f.userJpaEntity.userId = :userId") + int countFollowingByUserId(Long userId); } diff --git a/src/main/java/konkuk/thip/user/application/mapper/FollowQueryMapper.java b/src/main/java/konkuk/thip/user/application/mapper/FollowQueryMapper.java index 71f011d2a..4633e8b2e 100644 --- a/src/main/java/konkuk/thip/user/application/mapper/FollowQueryMapper.java +++ b/src/main/java/konkuk/thip/user/application/mapper/FollowQueryMapper.java @@ -4,11 +4,13 @@ import konkuk.thip.user.adapter.in.web.response.UserFollowingResponse; import konkuk.thip.user.application.port.out.dto.UserQueryDto; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; @Mapper(componentModel = "spring") public interface FollowQueryMapper { UserFollowersResponse.FollowerDto toFollowerDto(UserQueryDto dto); + @Mapping(target = "isFollowing", constant = "true") UserFollowingResponse.FollowingDto toFollowingDto(UserQueryDto dto); } \ No newline at end of file diff --git a/src/main/java/konkuk/thip/user/application/port/out/FollowingQueryPort.java b/src/main/java/konkuk/thip/user/application/port/out/FollowingQueryPort.java index d144c8bf9..2deab9dc5 100644 --- a/src/main/java/konkuk/thip/user/application/port/out/FollowingQueryPort.java +++ b/src/main/java/konkuk/thip/user/application/port/out/FollowingQueryPort.java @@ -12,5 +12,7 @@ public interface FollowingQueryPort { List getLatestFollowerImageUrls(Long userId, int size); boolean isFollowingUser(Long userId, Long targetUserId); + + int getFollowingCountByUser(Long userId); } diff --git a/src/main/java/konkuk/thip/user/application/service/following/UserGetFollowService.java b/src/main/java/konkuk/thip/user/application/service/following/UserGetFollowService.java index 29789f126..8605599bc 100644 --- a/src/main/java/konkuk/thip/user/application/service/following/UserGetFollowService.java +++ b/src/main/java/konkuk/thip/user/application/service/following/UserGetFollowService.java @@ -39,6 +39,7 @@ public UserFollowersResponse getUserFollowers(Long userId, String cursor, int si return UserFollowersResponse.builder() .followers(followers) + .totalFollowerCount(user.getFollowerCount()) .nextCursor(result.nextCursor()) .isLast(!result.hasNext()) .build(); @@ -48,6 +49,7 @@ public UserFollowersResponse getUserFollowers(Long userId, String cursor, int si @Transactional(readOnly = true) public UserFollowingResponse getMyFollowing(Long userId, String cursor, int size) { User user = userCommandPort.findById(userId); + int totalFollowingCount = followingQueryPort.getFollowingCountByUser(user.getId()); CursorBasedList result = followingQueryPort.getFollowingByUserId( user.getId(), cursor, Math.min(size, MAX_PAGE_SIZE) @@ -59,6 +61,7 @@ public UserFollowingResponse getMyFollowing(Long userId, String cursor, int size return UserFollowingResponse.builder() .followings(following) + .totalFollowingCount(totalFollowingCount) .nextCursor(result.nextCursor()) .isLast(!result.hasNext()) .build();