Skip to content

Commit

Permalink
fix: helpful cnt
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 3, 2024
1 parent 49193c1 commit 4e2be01
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ReviewFindUseCase {
private final OrderQueryService orderQueryService;
private final JwtUtil jwtUtil;

public List<ReviewInfo> findAllReviews(String accessToken) {
public List<ReviewInfo> findAllReviews(String accessToken, Long menuId) {

String email = jwtUtil.getEmail(accessToken);
User myUser = userQueryService.findByEmail(email);
Expand Down Expand Up @@ -86,9 +86,11 @@ public List<ReviewInfo> findAllReviews(String accessToken) {

boolean isMine = user.getUserId().equals(myUser.getUserId());
boolean helpfulYn = reviewQueryService.countLikeCountByMine(user.getUserId(), review.getId()) > 0;
Integer helpfulCnt = reviewQueryService.countAllLikeCount(review.getId());

ReviewInfo reviewInfo = new ReviewInfo(id, name, picture, rating, content, reviewImages,
likeCount, storeName, menuNameList, hourDifference, dayDifference, weekDifference, isMine, helpfulYn);
likeCount, store.getId(), storeName, menuNameList, hourDifference, dayDifference, weekDifference,
isMine, helpfulYn, helpfulCnt);
reviewInfos.add(reviewInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public record ReviewInfo(Long reviewId,
String content,
List<String> image,
String likeCount,
Long storeId,
String storeName,
List<String> menuName,
Integer beforeHours,
Integer beforeDay,
Integer beforeWeek,
Boolean isMine,
Boolean helpfulYn) {
Boolean helpfulYn,
Integer helpfulCnt) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ReviewController {
private final ReviewSaveUseCase reviewSaveUseCase;

// 리뷰 조회
@GetMapping
@GetMapping("/{menuId}")
@ApiResponses(
value = {
@ApiResponse(
Expand All @@ -40,10 +40,11 @@ public class ReviewController {
)
@Operation(summary = "전체 리뷰 확인 API", description = "전체 리뷰 확인 API 입니다.")
public ApplicationResponse<List<ReviewInfo>> getReviewInfo(
@RequestHeader(AuthConsts.ACCESS_TOKEN_HEADER) String accessToken
@RequestHeader(AuthConsts.ACCESS_TOKEN_HEADER) String accessToken,
@PathVariable Long menuId
) {

List<ReviewInfo> infos = reviewFindUseCase.findAllReviews(accessToken);
List<ReviewInfo> infos = reviewFindUseCase.findAllReviews(accessToken, menuId);
return ApplicationResponse.ok(infos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface ReviewLikeRepository extends JpaRepository<ReviewLike, Long> {

Integer countAllByUserUserIdAndReviewId(Long userId, Long reviewId);

Integer countAllByReviewIdAndUserUserId(Long reviewId, Long userId);
Integer countAllByReviewId(Long reviewId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public Long findLikeCountByReviewId(Long reviewId) {
return reviewLikeRepository.countByReviewId(reviewId);
}

public Integer countAllLikeCount(Long reviewId) {
return reviewLikeRepository.countAllByReviewId(reviewId);
}

public Integer countLikeCountByMine(Long userId, Long reviewId) {
return reviewLikeRepository.countAllByUserUserIdAndReviewId(userId, reviewId);
}
Expand All @@ -58,7 +62,7 @@ public void saveReviewLike(ReviewLike reviewLike) {
}

public Integer countReviewLikeAndUserId(Long reviewId, Long userId) {
return reviewLikeRepository.countAllByReviewIdAndUserUserId(reviewId, userId);
return reviewLikeRepository.countAllByUserUserIdAndReviewId(userId, reviewId);
}

public void deleteReview(Long id) {
Expand Down

0 comments on commit 4e2be01

Please sign in to comment.