File tree Expand file tree Collapse file tree
apps/commerce-api/src/main/java/com/loopers/application Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package com .loopers .application .event .like ;
2+
3+ import com .loopers .application .like .LikeCreateEvent ;
4+ import com .loopers .domain .product .Product ;
5+ import com .loopers .domain .product .ProductRepository ;
6+ import com .loopers .support .error .CoreException ;
7+ import com .loopers .support .error .ErrorType ;
8+ import lombok .RequiredArgsConstructor ;
9+ import org .springframework .stereotype .Component ;
10+ import org .springframework .transaction .annotation .Propagation ;
11+ import org .springframework .transaction .annotation .Transactional ;
12+ import org .springframework .transaction .event .TransactionPhase ;
13+ import org .springframework .transaction .event .TransactionalEventListener ;
14+
15+ @ Component
16+ @ RequiredArgsConstructor
17+ public class LikeEventHandler {
18+ private final ProductRepository productRepository ;
19+
20+ @ Transactional (propagation = Propagation .REQUIRES_NEW )
21+ @ TransactionalEventListener (phase = TransactionPhase .AFTER_COMMIT )
22+ public void onLikeCreated (LikeCreateEvent event ) {
23+ Product product = productRepository .findById (event .productId ()).orElseThrow (
24+ () -> new CoreException (ErrorType .NOT_FOUND , "존재하지 않는 상품입니다." )
25+ );
26+
27+ product .addLikeCount ();
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ package com .loopers .application .like ;
2+
3+ public record LikeCreateEvent (Long userId , Long productId ) {
4+ }
Original file line number Diff line number Diff line change 22
33import com .loopers .domain .like .Like ;
44import com .loopers .domain .like .LikeRepository ;
5- import com .loopers .domain .product .Product ;
65import com .loopers .domain .product .ProductRepository ;
76import com .loopers .domain .user .UserRepository ;
87import com .loopers .interfaces .api .like .LikeV1Dto ;
@@ -35,7 +34,7 @@ public LikeInfo doLike(LikeV1Dto.LikeRequest request) {
3534 () -> new CoreException (ErrorType .NOT_FOUND , "존재하지 않는 유저입니다." )
3635 );
3736
38- Product product = productRepository .findById (productId ).orElseThrow (
37+ productRepository .findById (productId ).orElseThrow (
3938 () -> new CoreException (ErrorType .NOT_FOUND , "존재하지 않는 상품입니다." )
4039 );
4140
You can’t perform that action at this time.
0 commit comments