Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public BaseResponse<UserFollowingResponse> showMyFollowing(
return BaseResponse.ok(userGetFollowUsecase.getMyFollowing(userId, cursor, size));
}

@Deprecated
@Operation(
summary = "팔로잉 여부 조회",
description = "특정 사용자가 다른 사용자를 팔로우하고 있는지 확인합니다."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Builder
public record UserFollowersResponse(
List<FollowerDto> followers,
Integer totalFollowerCount,
String nextCursor,
boolean isLast
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Builder
public record UserFollowingResponse(
List<FollowingDto> followings,
Integer totalFollowingCount,
String nextCursor,
boolean isLast
) {
Expand All @@ -16,7 +17,8 @@ public record FollowingDto(
String nickname,
String profileImageUrl,
String aliasName,
String aliasColor
String aliasColor,
boolean isFollowing
){
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public List<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<FollowingJpaEntity, Long>, 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface FollowingQueryPort {
List<String> getLatestFollowerImageUrls(Long userId, int size);

boolean isFollowingUser(Long userId, Long targetUserId);

int getFollowingCountByUser(Long userId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<UserQueryDto> result = followingQueryPort.getFollowingByUserId(
user.getId(), cursor, Math.min(size, MAX_PAGE_SIZE)
Expand All @@ -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();
Expand Down