Skip to content

Commit

Permalink
refactor: RateRepository의 findByMemberIdAndOrderItemId 메서드 반환값을 Rate에…
Browse files Browse the repository at this point in the history
…서 int로 수정
  • Loading branch information
dahyen0o committed Aug 26, 2023
1 parent bd20b44 commit 91bd4fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gugucon.shopping.rate.dto.response;

import com.gugucon.shopping.rate.domain.entity.Rate;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -11,9 +10,9 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RateDetailResponse {

private short score;
private int score;

public static RateDetailResponse from(final Rate rate) {
return new RateDetailResponse(rate.getScore());
public static RateDetailResponse from(final int rate) {
return new RateDetailResponse(rate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public interface RateRepository extends JpaRepository<Rate, Long> {
@Query("SELECT r.score FROM Rate r INNER JOIN r.orderItem oi WHERE oi.productId = :productId")
List<Integer> findScoresByProductId(final Long productId);

@Query("SELECT r FROM Order o " +
@Query("SELECT r.score FROM Order o " +
"INNER JOIN o.orderItems oi " +
"INNER JOIN Rate r ON oi.id = r.orderItem.id " +
"WHERE o.memberId = :memberId " +
"AND oi.id = :orderItemId")
Optional<Rate> findByMemberIdAndOrderItemId(final Long memberId, final Long orderItemId);
Optional<Integer> findByMemberIdAndOrderItemId(final Long memberId, final Long orderItemId);

@Query("SELECT r.score FROM Member m " +
"INNER JOIN Order o ON o.memberId = m.id " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public RateResponse getRates(final Long productId) {
}

public RateDetailResponse getRateDetail(final Long memberId, final Long orderItemId) {
final Rate rate = rateRepository.findByMemberIdAndOrderItemId(memberId, orderItemId)
final int score = rateRepository.findByMemberIdAndOrderItemId(memberId, orderItemId)
.orElseThrow(() -> new ShoppingException(ErrorCode.INVALID_RATE));
return RateDetailResponse.from(rate);
return RateDetailResponse.from(score);
}

public RateResponse getCustomRate(final Long productId, final MemberPrincipal principal) {
Expand Down

1 comment on commit 91bd4fb

@dongjoo0-0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:+1

Please sign in to comment.