-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 과정별 인터페이스 생성 - 파사드 패턴 적용
- Loading branch information
Showing
18 changed files
with
288 additions
and
40 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/org/store/clothstar/order/service/OrderSave/OrderCreator.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,10 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.member.domain.Address; | ||
import org.store.clothstar.member.domain.Member; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.dto.request.CreateOrderRequest; | ||
|
||
public interface OrderCreator { | ||
Order createOrder(CreateOrderRequest request,Member member,Address address); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/store/clothstar/order/service/OrderSave/OrderCreatorImpl.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,17 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.store.clothstar.member.domain.Address; | ||
import org.store.clothstar.member.domain.Member; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.dto.request.CreateOrderRequest; | ||
|
||
|
||
@Service | ||
public class OrderCreatorImpl implements OrderCreator { | ||
|
||
@Override | ||
public Order createOrder(CreateOrderRequest request,Member member,Address address) { | ||
return request.toOrder(member, address); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/store/clothstar/order/service/OrderSave/OrderDetailAdder.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,8 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
|
||
public interface OrderDetailAdder { | ||
void addOrderDetail(Order order, OrderDetail orderDetail); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/store/clothstar/order/service/OrderSave/OrderDetailAdderImpl.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,13 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
|
||
@Service | ||
public class OrderDetailAdderImpl implements OrderDetailAdder { | ||
@Override | ||
public void addOrderDetail(Order order, OrderDetail orderDetail) { | ||
order.addOrderDetail(orderDetail); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/store/clothstar/order/service/OrderSave/OrderDetailCreator.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,11 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
import org.store.clothstar.order.dto.request.CreateOrderDetailRequest; | ||
import org.store.clothstar.product.entity.ProductEntity; | ||
import org.store.clothstar.productLine.entity.ProductLineEntity; | ||
|
||
public interface OrderDetailCreator { | ||
OrderDetail createOrderDetail(CreateOrderDetailRequest createOrderDetailRequest, Order order, ProductLineEntity productLineEntity, ProductEntity productEntity); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/store/clothstar/order/service/OrderSave/OrderDetailCreatorImpl.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,16 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
import org.store.clothstar.order.dto.request.CreateOrderDetailRequest; | ||
import org.store.clothstar.product.entity.ProductEntity; | ||
import org.store.clothstar.productLine.entity.ProductLineEntity; | ||
|
||
@Service | ||
public class OrderDetailCreatorImpl implements OrderDetailCreator { | ||
@Override | ||
public OrderDetail createOrderDetail(CreateOrderDetailRequest createOrderDetailRequest, Order order, ProductLineEntity productLineEntity, ProductEntity productEntity) { | ||
return createOrderDetailRequest.toOrderDetail(order, productLineEntity, productEntity); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/store/clothstar/order/service/OrderSave/OrderDetailValidator.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,8 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.order.dto.request.CreateOrderDetailRequest; | ||
import org.store.clothstar.product.entity.ProductEntity; | ||
|
||
public interface OrderDetailValidator { | ||
void validateOrderDetail(CreateOrderDetailRequest request, ProductEntity product); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/store/clothstar/order/service/OrderSave/OrderDetailValidatorImpl.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,17 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import org.store.clothstar.order.dto.request.CreateOrderDetailRequest; | ||
import org.store.clothstar.product.entity.ProductEntity; | ||
|
||
@Service | ||
public class OrderDetailValidatorImpl implements OrderDetailValidator{ | ||
@Override | ||
public void validateOrderDetail(CreateOrderDetailRequest request, ProductEntity product) { | ||
if (request.getQuantity() > product.getStock()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다."); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/store/clothstar/order/service/OrderSave/OrderPriceUpdater.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,8 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
|
||
public interface OrderPriceUpdater { | ||
void updateOrderPrice(Order order, OrderDetail orderDetail); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/store/clothstar/order/service/OrderSave/OrderPriceUpdaterImpl.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,17 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
|
||
@Service | ||
public class OrderPriceUpdaterImpl implements OrderPriceUpdater { | ||
@Override | ||
public void updateOrderPrice(Order order, OrderDetail orderDetail) { | ||
int newTotalProductsPrice = order.getTotalPrice().getProducts() + orderDetail.getPrice().getOneKindTotalPrice(); | ||
int newTotalPaymentPrice = | ||
order.getTotalPrice().getProducts() + order.getTotalPrice().getShipping() + orderDetail.getPrice().getOneKindTotalPrice(); | ||
|
||
order.getTotalPrice().updatePrices(newTotalProductsPrice, newTotalPaymentPrice); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/org/store/clothstar/order/service/OrderSave/OrderSaveFacade.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,95 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import org.store.clothstar.member.domain.Address; | ||
import org.store.clothstar.member.domain.Member; | ||
import org.store.clothstar.member.service.AddressService; | ||
import org.store.clothstar.member.service.MemberService; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.domain.OrderDetail; | ||
import org.store.clothstar.order.dto.request.CreateOrderDetailRequest; | ||
import org.store.clothstar.order.dto.request.CreateOrderRequest; | ||
import org.store.clothstar.order.dto.request.OrderRequestWrapper; | ||
import org.store.clothstar.product.entity.ProductEntity; | ||
import org.store.clothstar.product.service.ProductService; | ||
import org.store.clothstar.productLine.entity.ProductLineEntity; | ||
import org.store.clothstar.productLine.service.ProductLineService; | ||
|
||
@Service | ||
public class OrderSaveFacade { | ||
|
||
private final MemberService memberService; | ||
private final AddressService addressService; | ||
private final ProductService productService; | ||
private final ProductLineService productLineService; | ||
private final OrderCreator orderCreator; | ||
private final OrderDetailValidator orderDetailValidator; | ||
private final OrderDetailCreator orderDetailCreator; | ||
private final OrderDetailAdder orderDetailAdder; | ||
private final OrderSaver orderSaver; | ||
private final OrderPriceUpdater orderPriceUpdater; | ||
private final StockUpdater stockUpdater; | ||
|
||
|
||
public OrderSaveFacade( | ||
MemberService memberService, AddressService addressService | ||
, ProductService productService, ProductLineService productLineService | ||
, OrderCreator orderCreator | ||
, OrderDetailValidator orderDetailValidator | ||
, OrderDetailCreator orderDetailCreator | ||
, OrderDetailAdder orderDetailAdder | ||
, OrderSaver orderSaver | ||
, OrderPriceUpdater orderPriceUpdater | ||
, StockUpdater stockUpdater | ||
) { | ||
this.memberService = memberService; | ||
this.addressService = addressService; | ||
this.productService = productService; | ||
this.productLineService = productLineService; | ||
this.orderCreator=orderCreator; | ||
this.orderDetailValidator = orderDetailValidator; | ||
this.orderDetailCreator = orderDetailCreator; | ||
this.orderDetailAdder=orderDetailAdder; | ||
this.orderSaver=orderSaver; | ||
this.orderPriceUpdater=orderPriceUpdater; | ||
this.stockUpdater=stockUpdater; | ||
} | ||
|
||
@Transactional | ||
public Long saveOrder(OrderRequestWrapper orderRequestWrapper) { | ||
CreateOrderRequest createOrderRequest = orderRequestWrapper.getCreateOrderRequest(); | ||
CreateOrderDetailRequest createOrderDetailRequest = orderRequestWrapper.getCreateOrderDetailRequest(); | ||
Member member = memberService.getMemberByMemberId(createOrderRequest.getMemberId()); | ||
Address address = addressService.getAddressById(createOrderRequest.getAddressId()); | ||
ProductLineEntity productLineEntity = productLineService.findById(createOrderDetailRequest.getProductLineId()) | ||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "상품을 찾을 수 없습니다")); | ||
ProductEntity productEntity = productService.findById(createOrderDetailRequest.getProductId()) | ||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "상품 옵션을 찾을 수 없습니다")); | ||
|
||
// 요청 DTO로부터 주문 생성 | ||
Order order = orderCreator.createOrder(createOrderRequest,member,address); | ||
|
||
// 주문상세 생성 유효성 검사 | ||
orderDetailValidator.validateOrderDetail(createOrderDetailRequest,productEntity); | ||
|
||
// 주문상세 생성 | ||
OrderDetail orderDetail = orderDetailCreator.createOrderDetail(createOrderDetailRequest, order, productLineEntity, productEntity); | ||
|
||
// 주문에 주문상세 추가 | ||
orderDetailAdder.addOrderDetail(order, orderDetail); | ||
|
||
// 주문 저장 (orderDetail은 cascade 설정에 의해 자동 저장됨) | ||
orderSaver.saveOrder(order); | ||
|
||
// 주문 정보 업데이트 | ||
orderPriceUpdater.updateOrderPrice(order,orderDetail); | ||
|
||
// 주문 수량만큼 상품 재고 차감 | ||
stockUpdater.updateStock(productEntity,orderDetail.getQuantity()); | ||
|
||
return order.getOrderId(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/store/clothstar/order/service/OrderSave/OrderSaver.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,7 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.order.domain.Order; | ||
|
||
public interface OrderSaver { | ||
void saveOrder(Order order); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/store/clothstar/order/service/OrderSave/OrderSaverImpl.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,18 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.store.clothstar.order.domain.Order; | ||
import org.store.clothstar.order.repository.order.OrderUserRepository; | ||
|
||
@Service | ||
public class OrderSaverImpl implements OrderSaver{ | ||
private final OrderUserRepository orderUserRepository; | ||
|
||
public OrderSaverImpl(OrderUserRepository orderUserRepository) { | ||
this.orderUserRepository = orderUserRepository; | ||
} | ||
@Override | ||
public void saveOrder(Order order) { | ||
orderUserRepository.save(order); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/store/clothstar/order/service/OrderSave/StockUpdater.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,7 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.store.clothstar.product.entity.ProductEntity; | ||
|
||
public interface StockUpdater { | ||
void updateStock(ProductEntity product, int quantity); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/store/clothstar/order/service/OrderSave/StockUpdaterImpl.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,20 @@ | ||
package org.store.clothstar.order.service.OrderSave; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.store.clothstar.product.entity.ProductEntity; | ||
import org.store.clothstar.product.service.ProductService; | ||
|
||
@Service | ||
public class StockUpdaterImpl implements StockUpdater { | ||
|
||
private static ProductService productService; | ||
|
||
public StockUpdaterImpl(ProductService productService){ | ||
this.productService=productService; | ||
} | ||
|
||
@Override | ||
public void updateStock(ProductEntity product, int quantity) { | ||
productService.updateProductStock(product, quantity); | ||
} | ||
} |
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