File tree Expand file tree Collapse file tree
apps/commerce-api/src/main/java/com/loopers/application/product Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import com .loopers .support .error .CoreException ;
99import com .loopers .support .error .ErrorType ;
1010import lombok .RequiredArgsConstructor ;
11+ import org .springframework .cache .annotation .CacheEvict ;
1112import org .springframework .cache .annotation .Cacheable ;
1213import org .springframework .stereotype .Component ;
1314import org .springframework .transaction .annotation .Transactional ;
1415
16+ import java .math .BigDecimal ;
1517import java .util .List ;
1618
1719@ Component
@@ -67,4 +69,19 @@ public List<ProductInfo> searchProductsByCondition(ProductV1Dto.SearchProductReq
6769 .map (ProductInfo ::from )
6870 .toList ();
6971 }
72+
73+ @ Transactional
74+ @ CacheEvict (value = "product" , key = "#request.id()" )
75+ public ProductInfo changePrice (ProductV1Dto .ChangePriceRequest request ) {
76+ Long id = request .id ();
77+ BigDecimal newPrice = request .newPrice ();
78+
79+ Product product = productRepository .findById (id ).orElseThrow (
80+ () -> new CoreException (ErrorType .NOT_FOUND , "존재하지 않는 상품입니다." )
81+ );
82+
83+ Product changedProduct = product .changePrice (newPrice );
84+
85+ return ProductInfo .from (changedProduct );
86+ }
7087}
You can’t perform that action at this time.
0 commit comments