Skip to content

Commit d9322e1

Browse files
committed
feat: Order 및 Stock 이벤트에 상품명 필드 추가 및 랭킹 매핑 메서드 확장
- `ProductStockEvent`와 `OrderCreatedEvent`의 상품명(`productName`) 필드 추가로 이벤트 정보를 확장 - 랭킹 엔티티 매핑을 위한 `RankingInfo` 생성 메서드 확장 (주간 및 월간 랭킹 지원)
1 parent 21dc4d2 commit d9322e1

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/order/event/OrderCreatedEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.UUID;
10-
import java.util.function.Function;
1110
import java.util.stream.Collectors;
1211

1312
public record OrderCreatedEvent(
@@ -22,7 +21,7 @@ public record OrderCreatedEvent(
2221
Long couponId
2322
) {
2423

25-
public record OrderItemInfo(Long productId, int quantity, long price, int remainStock) {
24+
public record OrderItemInfo(Long productId, String productName, int quantity, long price, int remainStock) {
2625

2726
}
2827

@@ -46,6 +45,7 @@ public static OrderCreatedEvent of(
4645
Product product = productMap.get(item.getProductId());
4746
return new OrderItemInfo(
4847
item.getProductId(),
48+
product != null ? product.getName() : "Unknown",
4949
item.getQuantity(),
5050
product != null ? product.getPrice().getValue() : 0,
5151
product != null ? product.getStock() : 0

apps/commerce-api/src/main/java/com/loopers/application/order/event/OrderSalesAggregateListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void handleOrderCreated(OrderCreatedEvent event) {
2424

2525
ProductStockEvent kafkaEvent = ProductStockEvent.of(
2626
item.productId(),
27+
item.productName(),
2728
item.quantity(),
2829
item.remainStock(),
2930
item.price()

apps/commerce-api/src/main/java/com/loopers/application/rank/RankingInfo.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.loopers.application.rank;
22

33
import com.loopers.domain.product.Product;
4+
import com.loopers.domain.rank.monthly.MonthlyRankingMV;
5+
import com.loopers.domain.rank.weekly.WeeklyRankingMV;
46

57
public record RankingInfo(
68
Long productId,
@@ -19,4 +21,24 @@ public static RankingInfo of(Product product, int currentRank) {
1921
currentRank
2022
);
2123
}
24+
25+
public static RankingInfo from(WeeklyRankingMV mv) {
26+
return new RankingInfo(
27+
mv.getProductId(),
28+
mv.getProductName(),
29+
mv.getPrice(),
30+
mv.isSoldOut(),
31+
mv.getCurrentRank()
32+
);
33+
}
34+
35+
public static RankingInfo from(MonthlyRankingMV mv) {
36+
return new RankingInfo(
37+
mv.getProductId(),
38+
mv.getProductName(),
39+
mv.getPrice(),
40+
mv.isSoldOut(),
41+
mv.getCurrentRank()
42+
);
43+
}
2244
}

modules/kafka/src/main/java/com/loopers/event/ProductStockEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
public record ProductStockEvent(
77
String eventId,
88
Long productId,
9+
String productName,
910
int sellQuantity,
1011
int currentStock,
1112
long price,
1213
LocalDateTime createdAt
1314
) {
14-
public static ProductStockEvent of(Long productId, int sellQuantity, int currentStock, long price) {
15+
public static ProductStockEvent of(Long productId, String productName, int sellQuantity, int currentStock, long price) {
1516
return new ProductStockEvent(
1617
UUID.randomUUID().toString(),
1718
productId,
19+
productName,
1820
sellQuantity,
1921
currentStock,
2022
price,

0 commit comments

Comments
 (0)