Skip to content

Commit aa6aed1

Browse files
authored
Merge pull request #119 from Team-baebae/feature/followCount
feat : 팔로잉,팔로워 수 조회 API 기능 개발
2 parents f69f028 + 21a51bb commit aa6aed1

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

.idea/compiler.xml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baebae-BE/src/main/java/com/web/baebaeBE/domain/Follow/controller/FollowController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public ResponseEntity<FollowResponse.hasNewFollowersResponse> getHasNewFollowers
6767
return ResponseEntity.ok(followService.hasFollowers(memberId));
6868
}
6969

70+
@GetMapping("followers/count/{memberId}")
71+
public ResponseEntity<FollowResponse.FollowCountResponse> getFollowerCount(
72+
@PathVariable Long memberId
73+
) {
74+
return ResponseEntity.ok(followService.getFollowerCount(memberId));
75+
}
76+
7077
@PatchMapping("followers/relation/update/{memberId}")
7178
public ResponseEntity<Void> updateFollowRelation(
7279
@PathVariable Long memberId

baebae-BE/src/main/java/com/web/baebaeBE/domain/Follow/controller/api/FollowApi.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,30 @@ public ResponseEntity<FollowResponse.hasNewFollowersResponse> getHasNewFollowers
196196
@PathVariable Long memberId
197197
);
198198

199+
@Operation(
200+
summary = "팔로잉, 팔로워 수 조회",
201+
description = "해당 유저의 팔로잉, 팔로워 수를 조회한다. (팔로워 수, 팔로잉 수)",
202+
security = @SecurityRequirement(name = "bearerAuth")
203+
)
204+
@Parameter(
205+
in = ParameterIn.HEADER,
206+
name = "Authorization", required = true,
207+
schema = @Schema(type = "string"),
208+
description = "Bearer [Access 토큰]")
209+
@ApiResponses(value = {
210+
@ApiResponse(responseCode = "200", description = "조회"),
211+
@ApiResponse(responseCode = "401", description = "토큰 인증 실패",
212+
content = @Content(mediaType = "application/json",
213+
examples = @ExampleObject(value = "{\n" +
214+
" \"errorCode\": \"T-002\",\n" +
215+
" \"message\": \"해당 토큰은 유효한 토큰이 아닙니다.\"\n" +
216+
"}"))
217+
)
218+
})
219+
@GetMapping("followers/count/{memberId}")
220+
public ResponseEntity<FollowResponse.FollowCountResponse> getFollowerCount(
221+
@PathVariable Long memberId
222+
);
199223
@Operation(
200224
summary = "새 팔로워들을 기존 팔로워들로 변경",
201225
description = "해당 멤버의 새로운 팔로워들을 기존 팔로워들로 변경한다.",

baebae-BE/src/main/java/com/web/baebaeBE/domain/Follow/dto/FollowResponse.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ public static isFollowingResponse of(boolean isFollow) {
4141
}
4242
}
4343

44+
@Getter
45+
@Setter
46+
@Builder
47+
@NoArgsConstructor
48+
@AllArgsConstructor
49+
public static class FollowCountResponse {
50+
private long followerCount;
51+
private long followingCount;
52+
53+
public static FollowCountResponse of(long followerCount, long followingCount) {
54+
return FollowCountResponse.builder()
55+
.followerCount(followerCount)
56+
.followingCount(followingCount)
57+
.build();
58+
}
59+
}
60+
4461
@Getter
4562
@Builder
4663
@NoArgsConstructor(access = AccessLevel.PROTECTED)

baebae-BE/src/main/java/com/web/baebaeBE/domain/Follow/repository/FollowRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public interface FollowRepository extends JpaRepository<Follow, Long> {
1919
// 중복 체크에 사용할 메서드
2020
boolean existsByFollowerIdAndFollowingId(Long followerId, Long followingId);
2121

22+
// 특정 사용자가 팔로우하는 사람 수
23+
long countByFollower_Id(Long memberId);
24+
25+
// 특정 사용자를 팔로우하는 사람 수
26+
long countByFollowing_Id(Long memberId);
27+
2228
@Query("SELECT fol " +
2329
"FROM Follow f " +
2430
"JOIN f.follower fol " +

baebae-BE/src/main/java/com/web/baebaeBE/domain/Follow/service/FollowService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ public void followMember(Long followerId, Long followingId) {
5353
followRepository.save(follow);
5454
}
5555

56+
public FollowResponse.FollowCountResponse getFollowerCount(Long memberId) {
57+
long followerCount = followRepository.countByFollower_Id(memberId);
58+
long followingCount = followRepository.countByFollowing_Id(memberId);
59+
60+
return FollowResponse.FollowCountResponse.of(followerCount, followingCount);
61+
}
62+
5663
public void deleteFollower(Long followerId, Long followingId) {
5764
Follow follow = followRepository.findByFollowerIdAndFollowingId(followerId, followingId)
5865
.orElseThrow(() -> new BusinessException(FollowException.NOT_EXIST_FOLLOW));

0 commit comments

Comments
 (0)