Skip to content

Commit

Permalink
Merge pull request #227 from Team-BC-1/refactor/rename-product-like-s…
Browse files Browse the repository at this point in the history
…ervice

ProductLikeService -> ProductLikeCommandService 로 Renaming
  • Loading branch information
vanillacake369 authored Feb 3, 2024
2 parents 5b21556 + 184c900 commit 0ea114d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +28,7 @@
@RequestMapping("/api/products")
public class ProductLikeController {

private final ProductLikeService productLikeService;
private final ProductLikeCommandService productLikeCommandService;

/**
* 상품 좋아요 요청
Expand All @@ -43,7 +43,7 @@ public RestResponse<ProductLikeResponseDto> 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);
}
Expand All @@ -61,7 +61,7 @@ public RestResponse<ProductDislikeResponseDto> 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);
}
Expand All @@ -80,7 +80,7 @@ public RestResponse<List<ProductLikesResponseDto>> productLikes(
@PageableDefault(size = 5) Pageable pageable
) {
OrderCriteriaValidator.validateOrderCriteria(Buy.class, pageable);
List<Product> products = productLikeService.productLikes(userDetails.getUser(), pageable);
List<Product> products = productLikeCommandService.productLikes(userDetails.getUser(), pageable);
List<ProductLikesResponseDto> response = products.stream().map(ProductMapper.INSTANCE::toProductLikesResponseDto).toList();
return RestResponse.success(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +31,7 @@ class ProductLikeControllerTest extends BaseMvcTest implements ProductTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private ProductLikeService productLikeService;
private ProductLikeCommandService productLikeCommandService;

@BeforeEach
void setUp() {
Expand All @@ -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))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("관싱상품을 등록합니다.")
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 0ea114d

Please sign in to comment.