Skip to content

Commit

Permalink
리뷰 개수 조회 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomeo184 committed Jan 6, 2024
1 parent 7a53238 commit 0f24161
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/com/offer/review/application/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.offer.post.domain.Post;
import com.offer.post.domain.PostRepository;
import com.offer.review.application.request.ReviewCreateRequest;
import com.offer.review.application.response.ReviewCountResponse;
import com.offer.review.application.response.ReviewInfoResponse;
import com.offer.review.application.response.ReviewInfoResponses;
import com.offer.review.domain.Review;
Expand Down Expand Up @@ -84,4 +85,15 @@ public ReviewInfoResponses getReviews(Long memberId, Role role, Long lastId, int
.hasNext(false)
.build();
}

@Transactional(readOnly = true)
public ReviewCountResponse getReviewCounts(Long memberId) {

Member member = memberRepository.getById(memberId);
int all = reviewRepository.countByRevieweeIdOrReviewerId(memberId, memberId);
int asSeller = reviewRepository.countByReviewerAndRevieweeIsBuyer(member, true);
int asBuyer = reviewRepository.countByRevieweeAndRevieweeIsBuyer(member, false);

return new ReviewCountResponse(all, asSeller, asBuyer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.offer.review.application.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class ReviewCountResponse {

private final int all;
private final int seller;
private final int buyer;
}
2 changes: 2 additions & 0 deletions src/main/java/com/offer/review/domain/ReviewRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
List<Review> findTop10ByReviewerOrRevieweeAndIdGreaterThanEqual(Member reviewer, Member reviewee, Long id);

List<Review> findTop10ByReviewerAndRevieweeIsBuyerAndIdGreaterThanEqual(Member reviewer, boolean revieweeIsBuyer, Long id);
int countByReviewerAndRevieweeIsBuyer(Member reviewer, boolean revieweeIsBuyer);

List<Review> findTop10ByRevieweeAndRevieweeIsBuyerAndIdGreaterThanEqual(Member reviewee, boolean revieweeIsBuyer, Long id);
int countByRevieweeAndRevieweeIsBuyer(Member reviewee, boolean revieweeIsBuyer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.offer.common.response.ResponseMessage;
import com.offer.review.application.ReviewService;
import com.offer.review.application.request.ReviewCreateRequest;
import com.offer.review.application.response.ReviewCountResponse;
import com.offer.review.application.response.ReviewInfoResponse;
import com.offer.review.application.response.ReviewInfoResponses;
import com.offer.review.domain.Role;
Expand Down Expand Up @@ -41,7 +42,6 @@ public ResponseEntity<ApiResponse<CommonCreationResponse>> createReview(
@Operation(summary = "리뷰 조회", security = {@SecurityRequirement(name = "jwt")})
@GetMapping("/reviews")
public ResponseEntity<ApiResponse<ReviewInfoResponses>> getReviews(
@Schema(hidden = true) @AuthenticationPrincipal LoginMember loginMember,
@RequestParam Long memberId,
@RequestParam(defaultValue = "ALL") String role,
@RequestParam(defaultValue = "1") Long lastId,
Expand All @@ -54,4 +54,17 @@ public ResponseEntity<ApiResponse<ReviewInfoResponses>> getReviews(
ApiResponse.of(ResponseMessage.SUCCESS, response)
);
}

@Operation(summary = "사용자 리뷰 개수 정보 조회", security = {@SecurityRequirement(name = "jwt")})
@GetMapping("/reviews/counts")
public ResponseEntity<ApiResponse<ReviewCountResponse>> getReviewCounts(
@RequestParam Long memberId
) {

ReviewCountResponse response = reviewService.getReviewCounts(memberId);

return ResponseEntity.ok(
ApiResponse.of(ResponseMessage.SUCCESS, response)
);
}
}

0 comments on commit 0f24161

Please sign in to comment.