11package com .loopers .application .product ;
22
3- import com .loopers .domain .actionlog .ActionType ;
43import com .loopers .domain .brand .BrandRepository ;
4+ import com .loopers .domain .outbox .AggregateType ;
5+ import com .loopers .domain .outbox .OutboxEvent ;
6+ import com .loopers .domain .outbox .OutboxType ;
7+ import com .loopers .domain .outbox .OutboxRepository ;
58import com .loopers .domain .product .Product ;
69import com .loopers .domain .product .ProductRepository ;
10+ import com .loopers .infrastructure .product .ProductViewKafkaProducer ;
711import com .loopers .interfaces .api .product .ProductV1Dto ;
812import com .loopers .support .error .CoreException ;
913import com .loopers .support .error .ErrorType ;
1014import lombok .RequiredArgsConstructor ;
1115import org .springframework .cache .annotation .CacheEvict ;
1216import org .springframework .cache .annotation .Cacheable ;
13- import org .springframework .context .ApplicationEventPublisher ;
1417import org .springframework .stereotype .Component ;
1518import org .springframework .transaction .annotation .Transactional ;
1619
2225public class ProductFacade {
2326 private final ProductRepository productRepository ;
2427 private final BrandRepository brandRepository ;
25- private final ApplicationEventPublisher publisher ;
26-
28+ private final OutboxRepository outBoxRepository ;
29+ private final ProductViewKafkaProducer kafkaProducer ;
2730
2831 @ Transactional
2932 public ProductInfo registerProduct (ProductV1Dto .ProductRequest request ) {
@@ -49,15 +52,20 @@ public List<ProductInfo> findAllProducts() {
4952 .toList ();
5053 }
5154
52- @ Transactional ( readOnly = true )
55+ @ Transactional
5356 @ Cacheable (value = "product" , key = "#id" )
5457 public ProductInfo findProductById (Long id ) {
5558 Product product = productRepository .findById (id ).orElseThrow (
5659 () -> new CoreException (ErrorType .NOT_FOUND , "찾고자 하는 상품이 존재하지 않습니다." )
5760 );
5861
59- // 유저 ID는 임시로 하드 코딩했습니다. 추후 인증/인가 기능이 추가되면 수정할 예정입니다.
60- publisher .publishEvent (new UserActionEvent (1L , product .getId (), ActionType .PRODUCT_LOOKED_UP ));
62+ OutboxEvent outBoxEvent = OutboxEvent .of (
63+ AggregateType .PRODUCT ,
64+ product .getId (),
65+ OutboxType .PRODUCT_VIEWED
66+ );
67+
68+ outBoxRepository .save (outBoxEvent );
6169
6270 return ProductInfo .from (product );
6371 }
0 commit comments