diff --git a/apps/commerce-api/src/main/java/com/loopers/application/admin/product/AdminProductAppService.java b/apps/commerce-api/src/main/java/com/loopers/application/admin/product/AdminProductAppService.java index 0a46ed576..4b9822016 100644 --- a/apps/commerce-api/src/main/java/com/loopers/application/admin/product/AdminProductAppService.java +++ b/apps/commerce-api/src/main/java/com/loopers/application/admin/product/AdminProductAppService.java @@ -5,6 +5,7 @@ import com.loopers.domain.product.OptionRepository; import com.loopers.domain.product.Product; import com.loopers.domain.product.ProductRepository; +import com.loopers.application.product.ProductCacheManager; import com.loopers.support.error.CoreException; import com.loopers.support.error.ErrorType; import lombok.RequiredArgsConstructor; @@ -18,6 +19,7 @@ public class AdminProductAppService { private final ProductRepository productRepository; private final OptionRepository optionRepository; + private final ProductCacheManager productCacheManager; @Transactional public Product create(Long brandId, String name, Money basePrice) { @@ -36,6 +38,7 @@ public Option createOption(Long productId, String name, Money additionalPrice, i public Product update(Long id, String name, Money basePrice) { Product product = getById(id); product.update(name, basePrice); + productCacheManager.evictProductCaches(id, product.getBrandId()); return product; } @@ -44,6 +47,7 @@ public void delete(Long id) { Product product = getById(id); product.delete(); deleteOptionsByProductId(id); + productCacheManager.evictProductCaches(id, product.getBrandId()); } @Transactional diff --git a/apps/commerce-api/src/main/java/com/loopers/application/product/CachedBrandProductPage.java b/apps/commerce-api/src/main/java/com/loopers/application/product/CachedBrandProductPage.java new file mode 100644 index 000000000..68f3c6614 --- /dev/null +++ b/apps/commerce-api/src/main/java/com/loopers/application/product/CachedBrandProductPage.java @@ -0,0 +1,38 @@ +package com.loopers.application.product; + +import com.loopers.domain.common.Money; +import com.loopers.domain.product.Product; +import lombok.Builder; +import lombok.Getter; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Getter +@Builder +@Jacksonized +public class CachedBrandProductPage { + private final List content; + private final long totalElements; + + @Getter + @Builder + @Jacksonized + public static class ProductSummary { + private final Long productId; + private final String productName; + private final Money basePrice; + private final boolean deleted; + private final long likeCount; + + public static ProductSummary from(Product product) { + return ProductSummary.builder() + .productId(product.getId()) + .productName(product.getName()) + .basePrice(product.getBasePrice()) + .deleted(product.isDeleted()) + .likeCount(product.getLikeCount()) + .build(); + } + } +} diff --git a/apps/commerce-api/src/main/java/com/loopers/application/product/CachedProductDetail.java b/apps/commerce-api/src/main/java/com/loopers/application/product/CachedProductDetail.java new file mode 100644 index 000000000..742650bf8 --- /dev/null +++ b/apps/commerce-api/src/main/java/com/loopers/application/product/CachedProductDetail.java @@ -0,0 +1,38 @@ +package com.loopers.application.product; + +import com.loopers.domain.common.Money; +import com.loopers.domain.product.Option; +import com.loopers.domain.product.Product; +import lombok.Builder; +import lombok.Getter; +import lombok.extern.jackson.Jacksonized; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +@Getter +@Builder +@Jacksonized +public class CachedProductDetail { + private final Long productId; + private final String productName; + private final Money basePrice; + private final boolean deleted; + private final Long brandId; + private final long likeCount; + private final List options; + + public static CachedProductDetail from(Product product, List