-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from Team-BC-1/fix/test/admin-create-coupon-p…
…roduct ProductService -> ProductCommandService, ProductQueryService 로 분리
- Loading branch information
Showing
11 changed files
with
72 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/bc1/gream/domain/product/service/command/ProductCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package bc1.gream.domain.product.service.command; | ||
|
||
import bc1.gream.domain.admin.dto.request.AdminProductRequestDto; | ||
import bc1.gream.domain.product.entity.Product; | ||
import bc1.gream.domain.product.repository.ProductRepository; | ||
import bc1.gream.global.common.ResultCase; | ||
import bc1.gream.global.exception.GlobalException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ProductCommandService { | ||
|
||
private final ProductRepository productRepository; | ||
|
||
public void addProduct(AdminProductRequestDto adminProductRequestDto) { | ||
String productName = adminProductRequestDto.name(); | ||
|
||
if (productRepository.existsByName(productName)) { | ||
throw new GlobalException(ResultCase.DUPLICATED_PRODUCT_NAME); | ||
} | ||
|
||
Product product = buildProductFromRequest(adminProductRequestDto); | ||
productRepository.save(product); | ||
} | ||
|
||
private Product buildProductFromRequest(AdminProductRequestDto adminProductRequestDto) { | ||
return Product.builder() | ||
.name(adminProductRequestDto.name()) | ||
.brand(adminProductRequestDto.brand()) | ||
.description(adminProductRequestDto.description()) | ||
.imageUrl(adminProductRequestDto.imageUrl()) | ||
.price(adminProductRequestDto.price()) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters