Skip to content

Commit

Permalink
feat: 도서와 관련된 리뷰 개수 조회 API 추가 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwooo committed Jun 3, 2024
1 parent 447184e commit fc6a406
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/jisungin/api/review/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public ApiResponse<SliceResponse<ReviewWithRatingResponse>> findBookReviews(
return ApiResponse.ok(reviewService.findBookReviews(isbn, OffsetLimit.of(page, size, order)));
}

@GetMapping("/books/{isbn}/reviews/count")
public ApiResponse<Long> findBookReviewsCount(@PathVariable String isbn) {
return ApiResponse.ok(reviewService.findBookReviewsCount(isbn));
}

@PostMapping("/reviews")
public ApiResponse<Void> createReview(@Valid @RequestBody ReviewCreateRequest request,
@Auth Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public SliceResponse<ReviewWithRatingResponse> findBookReviews(String isbn, Offs
offsetLimit.getOrder());
}

public Long findBookReviewsCount(String isbn) {
Book book = bookRepository.findById(isbn)
.orElseThrow(() -> new BusinessException(BOOK_NOT_FOUND));

return reviewRepository.countByBookId(book.getIsbn());
}

@Transactional
public void createReview(ReviewCreateServiceRequest request, Long userId) {
User user = userRepository.findById(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ PageResponse<ReviewContentResponse> findAllReviewContentOrderBy(

SliceResponse<ReviewWithRatingResponse> findAllByBookId(String isbn, Integer offset, Integer limit, String order);

Long countByBookId(String isbn);

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ private List<ReviewContentResponse> getReviewContents(
.fetch();
}

public Long countByBookId(String isbn) {
return queryFactory.select(review.count())
.from(review)
.join(review.book, book)
.where(book.isbn.eq(isbn))
.fetchOne();
}

private long getTotalCount(Long userId, Double rating) {
return queryFactory
.select(review.count())
Expand Down

0 comments on commit fc6a406

Please sign in to comment.