Skip to content

Commit 5c2a54f

Browse files
committed
feat: 좋아요 갯수 조회 API (사용자 Id, 상품 Id)
1 parent afcc411 commit 5c2a54f

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/domain/like/LikeRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public interface LikeRepository {
1010
void delete(Like like);
1111

1212
int countByProductId(Long productId);
13+
14+
int countByUserIdAndProductId(Long userId, Long productId);
1315
}

apps/commerce-api/src/main/java/com/loopers/infrastructure/like/LikeJpaRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface LikeJpaRepository extends JpaRepository<Like, Long> {
99
Optional<Like> findByUserIdAndProductId(Long userId, Long productId);
1010

1111
int countByProductId(Long productId);
12+
13+
int countByUserIdAndProductId(Long userId, Long productId);
1214
}

apps/commerce-api/src/main/java/com/loopers/infrastructure/like/LikeRepositoryImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ public void delete(Like like) {
3131
public int countByProductId(Long productId) {
3232
return likeJpaRepository.countByProductId(productId);
3333
}
34+
35+
@Override
36+
public int countByUserIdAndProductId(Long userId, Long productId) {
37+
return likeJpaRepository.countByUserIdAndProductId(userId, productId);
38+
}
3439
}

apps/commerce-api/src/test/java/com/loopers/domain/user/UserServiceIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void returnsUserEntity_when_user_exists() {
109109
userService.save(userEntity);
110110

111111
// act
112-
UserEntity foundUser = userService.getUserByLoginId(loginId);
112+
UserEntity foundUser = userService.findUserByLoginId(loginId);
113113

114114
// assert
115115
assertThat(foundUser).isNotNull();
@@ -127,7 +127,7 @@ void returnsNull_when_user_not_exists() {
127127

128128
// act
129129
final CoreException result = assertThrows(CoreException.class, () -> {
130-
userService.getUserByLoginId(loginId);
130+
userService.findUserByLoginId(loginId);
131131
});
132132

133133
// assert

0 commit comments

Comments
 (0)