Skip to content

Commit 982af43

Browse files
committed
feat: 상품 상세 조회시 상품 순위 함께 반환
1 parent c325c4d commit 982af43

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/interfaces/api/product/ProductV1Controller.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.loopers.application.product.ProductDetailInfo;
44
import com.loopers.application.product.ProductFacade;
55
import com.loopers.application.product.ProductInfo;
6+
import com.loopers.application.ranking.RankingFacade;
67
import com.loopers.interfaces.api.ApiResponse;
78
import lombok.RequiredArgsConstructor;
89
import org.springframework.data.domain.Page;
@@ -15,6 +16,7 @@
1516
public class ProductV1Controller implements ProductV1ApiSpec {
1617

1718
private final ProductFacade productFacade;
19+
private final RankingFacade rankingFacade;
1820

1921
@Override
2022
@GetMapping
@@ -31,7 +33,9 @@ public ApiResponse<ProductV1Dto.ProductResponse> getProducts(@RequestParam(requi
3133
public ApiResponse<ProductV1Dto.ProductDetailResponse> getProduct(@PathVariable Long productId) {
3234

3335
ProductDetailInfo product = productFacade.getProduct(productId);
34-
ProductV1Dto.ProductDetailResponse response = ProductV1Dto.ProductDetailResponse.from(product);
36+
rankingFacade.recordView(productId);
37+
Long rank = rankingFacade.findRank(productId, null);
38+
ProductV1Dto.ProductDetailResponse response = ProductV1Dto.ProductDetailResponse.from(product, rank);
3539
return ApiResponse.success(response);
3640
}
3741
}

apps/commerce-api/src/main/java/com/loopers/interfaces/api/product/ProductV1Dto.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@ public record ProductDetailResponse(
5353
String productName,
5454
String brandName,
5555
Long price,
56-
Long likeCount
56+
Long likeCount,
57+
Long rank
5758
) {
58-
public static ProductDetailResponse from(ProductDetailInfo productDetailInfo) {
59+
public static ProductDetailResponse from(ProductDetailInfo productDetailInfo, Long rank) {
5960
return new ProductDetailResponse(
6061
productDetailInfo.id(),
6162
productDetailInfo.name(),
6263
productDetailInfo.brandName(),
6364
productDetailInfo.price(),
64-
productDetailInfo.likeCount()
65+
productDetailInfo.likeCount(),
66+
rank
6567
);
6668
}
6769
}

0 commit comments

Comments
 (0)