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
6 changes: 3 additions & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public ResponseEntity<FollowResponse.hasNewFollowersResponse> getHasNewFollowers
return ResponseEntity.ok(followService.hasFollowers(memberId));
}

@GetMapping("followers/count/{memberId}")
public ResponseEntity<FollowResponse.FollowCountResponse> getFollowerCount(
@PathVariable Long memberId
) {
return ResponseEntity.ok(followService.getFollowerCount(memberId));
}

@PatchMapping("followers/relation/update/{memberId}")
public ResponseEntity<Void> updateFollowRelation(
@PathVariable Long memberId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,30 @@ public ResponseEntity<FollowResponse.hasNewFollowersResponse> getHasNewFollowers
@PathVariable Long memberId
);

@Operation(
summary = "팔로잉, 팔로워 수 조회",
description = "해당 유저의 팔로잉, 팔로워 수를 조회한다. (팔로워 수, 팔로잉 수)",
security = @SecurityRequirement(name = "bearerAuth")
)
@Parameter(
in = ParameterIn.HEADER,
name = "Authorization", required = true,
schema = @Schema(type = "string"),
description = "Bearer [Access 토큰]")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회"),
@ApiResponse(responseCode = "401", description = "토큰 인증 실패",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\n" +
" \"errorCode\": \"T-002\",\n" +
" \"message\": \"해당 토큰은 유효한 토큰이 아닙니다.\"\n" +
"}"))
)
})
@GetMapping("followers/count/{memberId}")
public ResponseEntity<FollowResponse.FollowCountResponse> getFollowerCount(
@PathVariable Long memberId
);
@Operation(
summary = "새 팔로워들을 기존 팔로워들로 변경",
description = "해당 멤버의 새로운 팔로워들을 기존 팔로워들로 변경한다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ public static isFollowingResponse of(boolean isFollow) {
}
}

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class FollowCountResponse {
private long followerCount;
private long followingCount;

public static FollowCountResponse of(long followerCount, long followingCount) {
return FollowCountResponse.builder()
.followerCount(followerCount)
.followingCount(followingCount)
.build();
}
}

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public interface FollowRepository extends JpaRepository<Follow, Long> {
// 중복 체크에 사용할 메서드
boolean existsByFollowerIdAndFollowingId(Long followerId, Long followingId);

// 특정 사용자가 팔로우하는 사람 수
long countByFollower_Id(Long memberId);

// 특정 사용자를 팔로우하는 사람 수
long countByFollowing_Id(Long memberId);

@Query("SELECT fol " +
"FROM Follow f " +
"JOIN f.follower fol " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public void followMember(Long followerId, Long followingId) {
followRepository.save(follow);
}

public FollowResponse.FollowCountResponse getFollowerCount(Long memberId) {
long followerCount = followRepository.countByFollower_Id(memberId);
long followingCount = followRepository.countByFollowing_Id(memberId);

return FollowResponse.FollowCountResponse.of(followerCount, followingCount);
}

public void deleteFollower(Long followerId, Long followingId) {
Follow follow = followRepository.findByFollowerIdAndFollowingId(followerId, followingId)
.orElseThrow(() -> new BusinessException(FollowException.NOT_EXIST_FOLLOW));
Expand Down