Skip to content

Commit 60b4f5d

Browse files
committed
feat: 팔로워 수, 팔로잉 수 조회 간단 구현
1 parent c23360e commit 60b4f5d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/main/java/com/example/log4u/domain/follow/repository/FollowRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ public interface FollowRepository extends JpaRepository<Follow, Long> {
1010
boolean existsByInitiatorIdAndTargetId(Long initiatorId, Long targetId);
1111

1212
void deleteByInitiatorIdAndTargetId(Long initiatorId, Long targetId);
13+
14+
// 기능 구현 초기용, 데이터 쌓이면 개선 필요
15+
Long countByInitiatorId(Long initiatorId);
16+
17+
Long countByTargetId(Long targetId);
1318
}

src/main/java/com/example/log4u/domain/follow/service/FollowService.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.example.log4u.domain.follow.service;
22

33
import org.springframework.stereotype.Service;
4+
import org.springframework.transaction.annotation.Transactional;
45

56
import com.example.log4u.domain.follow.entitiy.Follow;
67
import com.example.log4u.domain.follow.exception.FollowNotFoundException;
78
import com.example.log4u.domain.follow.repository.FollowRepository;
89
import com.example.log4u.domain.user.service.UserService;
910

10-
import jakarta.transaction.Transactional;
1111
import lombok.RequiredArgsConstructor;
1212

1313
@Service
@@ -42,13 +42,19 @@ private void validateFollow(Long userId, Long targetId) {
4242
}
4343
}
4444

45-
public Long getFollowerCount() {
46-
//TODO: 구현
47-
return 0L;
45+
/**
46+
* 나를 팔로우 하는 사람 수 조회
47+
* */
48+
@Transactional(readOnly = true)
49+
public Long getFollowerCount(Long userId) {
50+
return followRepository.countByTargetId(userId);
4851
}
4952

50-
public Long getFollowingCount() {
51-
//TODO: 구현
52-
return 0L;
53+
/**
54+
* 내가 팔로우하는 사람 수 조회
55+
* */
56+
@Transactional(readOnly = true)
57+
public Long getFollowingCount(Long userId) {
58+
return followRepository.countByInitiatorId(userId);
5359
}
5460
}

0 commit comments

Comments
 (0)