diff --git a/src/main/java/bc1/gream/domain/admin/controller/AdminController.java b/src/main/java/bc1/gream/domain/admin/controller/AdminController.java index 538b69f9..dea2a043 100644 --- a/src/main/java/bc1/gream/domain/admin/controller/AdminController.java +++ b/src/main/java/bc1/gream/domain/admin/controller/AdminController.java @@ -7,11 +7,11 @@ import bc1.gream.domain.admin.dto.response.AdminCreateCouponResponseDto; import bc1.gream.domain.admin.dto.response.AdminGetRefundResponseDto; import bc1.gream.domain.admin.dto.response.AdminProductResponseDto; -import bc1.gream.domain.user.mapper.RefundMapper; import bc1.gream.domain.coupon.entity.Coupon; import bc1.gream.domain.coupon.mapper.CouponMapper; import bc1.gream.domain.coupon.provider.CouponProvider; -import bc1.gream.domain.product.service.query.ProductService; +import bc1.gream.domain.product.service.command.ProductCommandService; +import bc1.gream.domain.user.mapper.RefundMapper; import bc1.gream.domain.user.service.command.RefundCommandService; import bc1.gream.domain.user.service.query.RefundQueryService; import bc1.gream.global.common.RestResponse; @@ -32,7 +32,7 @@ @RequestMapping("/api/admin") public class AdminController { - private final ProductService productService; + private final ProductCommandService productCommandService; private final RefundQueryService refundQueryService; private final RefundCommandService refundCommandService; private final CouponProvider couponProvider; @@ -53,7 +53,7 @@ public RestResponse> getRefunds(AdminGetRefundRe public RestResponse addProducts( @RequestBody AdminProductRequestDto adminProductRequestDto ) { - productService.addProduct(adminProductRequestDto); + productCommandService.addProduct(adminProductRequestDto); return RestResponse.success(new AdminProductResponseDto()); } diff --git a/src/main/java/bc1/gream/domain/product/controller/ProductLikeController.java b/src/main/java/bc1/gream/domain/product/controller/ProductLikeController.java index 3079a44d..44f91009 100644 --- a/src/main/java/bc1/gream/domain/product/controller/ProductLikeController.java +++ b/src/main/java/bc1/gream/domain/product/controller/ProductLikeController.java @@ -6,7 +6,7 @@ import bc1.gream.domain.product.dto.response.ProductLikesResponseDto; import bc1.gream.domain.product.entity.Product; import bc1.gream.domain.product.mapper.ProductMapper; -import bc1.gream.domain.product.service.command.ProductLikeService; +import bc1.gream.domain.product.service.command.ProductLikeCommandService; import bc1.gream.global.common.RestResponse; import bc1.gream.global.security.UserDetailsImpl; import bc1.gream.global.validator.OrderCriteriaValidator; @@ -28,7 +28,7 @@ @RequestMapping("/api/products") public class ProductLikeController { - private final ProductLikeService productLikeService; + private final ProductLikeCommandService productLikeCommandService; /** * 상품 좋아요 요청 @@ -43,7 +43,7 @@ public RestResponse likeProduct( @AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long productId ) { - productLikeService.likeProduct(userDetails.getUser(), productId); + productLikeCommandService.likeProduct(userDetails.getUser(), productId); ProductLikeResponseDto responseDto = ProductMapper.INSTANCE.toLikeResponseDto("관심상품 등록"); return RestResponse.success(responseDto); } @@ -61,7 +61,7 @@ public RestResponse dislikeProduct( @AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long productId ) { - productLikeService.dislikeProduct(userDetails.getUser(), productId); + productLikeCommandService.dislikeProduct(userDetails.getUser(), productId); ProductDislikeResponseDto responseDto = ProductMapper.INSTANCE.toDislikeResponseDto("관심상품 등록 해제"); return RestResponse.success(responseDto); } @@ -80,7 +80,7 @@ public RestResponse> productLikes( @PageableDefault(size = 5) Pageable pageable ) { OrderCriteriaValidator.validateOrderCriteria(Buy.class, pageable); - List products = productLikeService.productLikes(userDetails.getUser(), pageable); + List products = productLikeCommandService.productLikes(userDetails.getUser(), pageable); List response = products.stream().map(ProductMapper.INSTANCE::toProductLikesResponseDto).toList(); return RestResponse.success(response); } diff --git a/src/main/java/bc1/gream/domain/product/service/command/ProductLikeService.java b/src/main/java/bc1/gream/domain/product/service/command/ProductLikeCommandService.java similarity index 95% rename from src/main/java/bc1/gream/domain/product/service/command/ProductLikeService.java rename to src/main/java/bc1/gream/domain/product/service/command/ProductLikeCommandService.java index b0b1fb13..d61e6318 100644 --- a/src/main/java/bc1/gream/domain/product/service/command/ProductLikeService.java +++ b/src/main/java/bc1/gream/domain/product/service/command/ProductLikeCommandService.java @@ -16,13 +16,13 @@ @Service @RequiredArgsConstructor @Slf4j -public class ProductLikeService { +@Transactional +public class ProductLikeCommandService { private final ProductRepository productRepository; private final LikeProductRepository likeProductRepository; - @Transactional public void likeProduct(User user, Long productId) { Product product = getProductBy(productId); boolean hasNotLikedThisProduct = user.getLikeProducts().stream() @@ -32,7 +32,6 @@ public void likeProduct(User user, Long productId) { } } - @Transactional public void dislikeProduct(User user, Long productId) { Product product = getProductBy(productId); user.removeLikeProduct(product); diff --git a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java index 837eec11..11a50432 100644 --- a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java +++ b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java @@ -7,7 +7,7 @@ import bc1.gream.domain.admin.dto.request.AdminCreateCouponRequestDto; import bc1.gream.domain.coupon.entity.DiscountType; import bc1.gream.domain.coupon.provider.CouponProvider; -import bc1.gream.domain.product.service.query.ProductService; +import bc1.gream.domain.product.service.command.ProductCommandService; import bc1.gream.domain.user.entity.UserRole; import bc1.gream.domain.user.service.command.RefundCommandService; import bc1.gream.domain.user.service.query.RefundQueryService; @@ -37,7 +37,7 @@ class AdminControllerTest { @Autowired private ObjectMapper objectMapper; @MockBean - private ProductService productService; + private ProductCommandService productCommandService; @MockBean private RefundQueryService refundQueryService; @MockBean diff --git a/src/test/java/bc1/gream/domain/product/controller/command/ProductLikeControllerTest.java b/src/test/java/bc1/gream/domain/product/controller/command/ProductLikeControllerTest.java index 65f7d538..dacc2d51 100644 --- a/src/test/java/bc1/gream/domain/product/controller/command/ProductLikeControllerTest.java +++ b/src/test/java/bc1/gream/domain/product/controller/command/ProductLikeControllerTest.java @@ -7,7 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import bc1.gream.domain.product.controller.ProductLikeController; -import bc1.gream.domain.product.service.command.ProductLikeService; +import bc1.gream.domain.product.service.command.ProductLikeCommandService; import bc1.gream.global.security.WithMockCustomUser; import bc1.gream.test.BaseMvcTest; import bc1.gream.test.ProductTest; @@ -31,7 +31,7 @@ class ProductLikeControllerTest extends BaseMvcTest implements ProductTest { @Autowired private MockMvc mockMvc; @MockBean - private ProductLikeService productLikeService; + private ProductLikeCommandService productLikeCommandService; @BeforeEach void setUp() { @@ -43,7 +43,7 @@ void setUp() { @Test public void 사용자_관심상품_추가() throws Exception { // WHEN - productLikeService.likeProduct(TEST_USER, TEST_PRODUCT_ID); + productLikeCommandService.likeProduct(TEST_USER, TEST_PRODUCT_ID); // THEN this.mockMvc.perform(post("/api/products/{productId}/like", TEST_PRODUCT_ID)) @@ -54,7 +54,7 @@ void setUp() { @Test public void 사용자_관심상품_삭제() throws Exception { // WHEN - productLikeService.dislikeProduct(TEST_USER, TEST_PRODUCT_ID); + productLikeCommandService.dislikeProduct(TEST_USER, TEST_PRODUCT_ID); // THEN this.mockMvc.perform(delete("/api/products/{productId}/dislike", TEST_PRODUCT_ID)) diff --git a/src/test/java/bc1/gream/domain/product/service/command/ProductLikeServiceIntegrationTest.java b/src/test/java/bc1/gream/domain/product/service/command/ProductLikeCommandServiceIntegrationTest.java similarity index 86% rename from src/test/java/bc1/gream/domain/product/service/command/ProductLikeServiceIntegrationTest.java rename to src/test/java/bc1/gream/domain/product/service/command/ProductLikeCommandServiceIntegrationTest.java index 8ef57e8f..455e6b83 100644 --- a/src/test/java/bc1/gream/domain/product/service/command/ProductLikeServiceIntegrationTest.java +++ b/src/test/java/bc1/gream/domain/product/service/command/ProductLikeCommandServiceIntegrationTest.java @@ -18,10 +18,10 @@ @Disabled("통합테스트는 로컬에서만 실행합니다. 실행 시, SECRET KEY 에 대한 IntelliJ 환경변수를 설정해주어야 합니다.") @Transactional -class ProductLikeServiceIntegrationTest extends BaseIntegrationTest implements ProductTest, UserTest { +class ProductLikeCommandServiceIntegrationTest extends BaseIntegrationTest implements ProductTest, UserTest { @Autowired - private ProductLikeService productLikeService; + private ProductLikeCommandService productLikeCommandService; @Autowired private LikeProductRepository likeProductRepository; @@ -43,7 +43,7 @@ void tearDown() { User user = savedBuyer; // WHEN - productLikeService.likeProduct(user, product.getId()); + productLikeCommandService.likeProduct(user, product.getId()); // THEN boolean hasNotLikedThisProduct = user.getLikeProducts().stream() diff --git a/src/test/java/bc1/gream/domain/product/service/command/ProductLikeServiceTest.java b/src/test/java/bc1/gream/domain/product/service/command/ProductLikeCommandServiceTest.java similarity index 90% rename from src/test/java/bc1/gream/domain/product/service/command/ProductLikeServiceTest.java rename to src/test/java/bc1/gream/domain/product/service/command/ProductLikeCommandServiceTest.java index 34236531..930db2b7 100644 --- a/src/test/java/bc1/gream/domain/product/service/command/ProductLikeServiceTest.java +++ b/src/test/java/bc1/gream/domain/product/service/command/ProductLikeCommandServiceTest.java @@ -25,13 +25,13 @@ @ExtendWith(MockitoExtension.class) @Rollback(value = true) @Transactional -class ProductLikeServiceTest implements ProductTest, UserTest { +class ProductLikeCommandServiceTest implements ProductTest, UserTest { @Mock ProductRepository productRepository; @InjectMocks - ProductLikeService productLikeService; + ProductLikeCommandService productLikeCommandService; @Test @DisplayName("관싱상품을 등록합니다.") @@ -41,7 +41,7 @@ class ProductLikeServiceTest implements ProductTest, UserTest { given(productRepository.findById(TEST_PRODUCT_ID)).willReturn(Optional.of(TEST_PRODUCT)); // WHEN - productLikeService.likeProduct(TEST_USER, TEST_PRODUCT_ID); + productLikeCommandService.likeProduct(TEST_USER, TEST_PRODUCT_ID); // THEN boolean hasUserLikeProduct = TEST_USER.getLikeProducts().stream() @@ -61,7 +61,7 @@ class ProductLikeServiceTest implements ProductTest, UserTest { user.getLikeProducts().add(likeProduct); // WHEN - productLikeService.dislikeProduct(user, TEST_PRODUCT_ID); + productLikeCommandService.dislikeProduct(user, TEST_PRODUCT_ID); // THEN boolean hasUserLikeProduct = user.getLikeProducts().stream()