From ffcc255e9a67f49bb2107b151d94778e1d034f4e Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Wed, 29 Nov 2023 23:46:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20sold=20out,=20=EC=98=81=EC=97=85=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EC=97=AC=EB=B6=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/ExceptionCode.java | 4 +++- .../src/order/OrderServiceImpl.java | 21 +++++++++++++++++++ .../src/store/dto/StoreMapper.java | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java index eea8dba..1398041 100644 --- a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java +++ b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java @@ -27,7 +27,9 @@ public enum ExceptionCode { INVALID_INOUT(400, "Invalid inout."), CART_NOT_EDITABLE(400, "Cart is not editable."), COUPON_NOT_VALID(400, "Coupon is not valid."), - NOT_MY_CART(400, "Not my cart."); + NOT_MY_CART(400, "Not my cart."), + STORE_NOT_OPEN(400, "Store is not open."), + CART_SOLD_OUT(400, "Cart is sold out."); private int status; private String message; diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index a8fe88f..3983042 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -202,6 +202,7 @@ public TosspaymentMakeRes requestTossPayment(CustomUserDetails userDetails, Paym Coupon coupon = getCoupon(paymentReq.getCouponId()); verifyCoupon(user, coupon); + verifyCartSoldOut(cart); // Long amount = calculateAmount(store, paymentReq.getCarts(), paymentReq.getInout()); Long amount = calculateAmount2(cart); Order order = makeOrder(user, store, amount, cart, coupon); @@ -211,6 +212,12 @@ public TosspaymentMakeRes requestTossPayment(CustomUserDetails userDetails, Paym return orderMapper.orderToTosspaymentMakeRes(order); } + private void verifyCartSoldOut(Cart cart) { + if (cart.getCartItems().stream().anyMatch(cartItem -> cartItem.getFoodie().isSoldOut())) { + throw new BusinessLogicException(ExceptionCode.CART_SOLD_OUT); + } + } + private void verifyCoupon(UserInfo user, Coupon coupon) { isCoupon(coupon); isUserCoupon(user, coupon); @@ -590,11 +597,25 @@ private Store getStore(Long storeId) { } private void verifyCartAddReq(Foodie foodie, CartAddReq cartAddReq) { + verifyStoreOpen(foodie.getFoodieCategory().getStore()); + verifyFoodyNotSoldOut(foodie); verifyOption(foodie, cartAddReq.getOptions()); verifyEssentialOption(foodie, cartAddReq.getOptions()); verifyInout(cartAddReq.getInout()); } + private void verifyFoodyNotSoldOut(Foodie foodie) { + if (foodie.isSoldOut()) { + throw new BusinessLogicException(ExceptionCode.FOODY_NOT_FOUND); + } + } + + private void verifyStoreOpen(Store store) { + if (!store.isStatus()) { + throw new BusinessLogicException(ExceptionCode.STORE_NOT_OPEN); + } + } + private void verifyInout(Long inout) { if (!inout.equals(EAT_IN) && !inout.equals(TAKE_OUT)) { throw new BusinessLogicException(ExceptionCode.INVALID_INOUT); diff --git a/src/main/java/com/readyvery/readyverydemo/src/store/dto/StoreMapper.java b/src/main/java/com/readyvery/readyverydemo/src/store/dto/StoreMapper.java index 0f27300..86495cc 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/store/dto/StoreMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/store/dto/StoreMapper.java @@ -40,6 +40,7 @@ private MenuDto categoryToMenuDto(FoodieCategory category) { .category(category.getName()) .menuItems(category.getFoodies() .stream() + .filter(foodie -> !foodie.isSoldOut()) .map(this::foodieToMenuItems) .toList()) .build(); From 207455798ef249a15f388b07b3c0dd797af3cd2e Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Wed, 29 Nov 2023 23:53:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat:=20cart=20inout=20=EB=8B=A4=EB=A6=84?= =?UTF-8?q?=20=EC=97=AC=EB=B6=80=20=ED=8C=90=EB=8B=A8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/ExceptionCode.java | 3 ++- .../readyverydemo/src/order/OrderServiceImpl.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java index 1398041..0d20fe7 100644 --- a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java +++ b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java @@ -29,7 +29,8 @@ public enum ExceptionCode { COUPON_NOT_VALID(400, "Coupon is not valid."), NOT_MY_CART(400, "Not my cart."), STORE_NOT_OPEN(400, "Store is not open."), - CART_SOLD_OUT(400, "Cart is sold out."); + CART_SOLD_OUT(400, "Cart is sold out."), + CART_INOUT_NOT_MATCH(400, "Cart inout is not match."); private int status; private String message; diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 3983042..c04e1a0 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -101,7 +101,7 @@ public CartAddRes addCart(CustomUserDetails userDetails, CartAddReq cartAddReq) Cart cart = cartRepository.findByUserInfoAndIsDeletedFalseAndIsOrderedFalse(user) .orElseGet(() -> makeCart(user, store, cartAddReq.getInout())); - verifyCart(cart); + verifyCart(cart, cartAddReq.getInout()); verifyItemsInCart(cart, store, cartAddReq.getInout()); CartItem cartItem = makeCartItem(cart, foodie, cartAddReq.getCount()); List cartOptions = cartAddReq.getOptions().stream() @@ -133,7 +133,7 @@ private void changeCartStore(Cart cart, Store store, Long inout) { @Override public CartEidtRes editCart(CustomUserDetails userDetails, Long idx, Long count) { CartItem cartItem = getCartItem(idx); - verifyCart(cartItem.getCart()); + verifyCart(cartItem.getCart(), null); verifyCartItem(cartItem, userDetails); editCartItem(cartItem, count); @@ -141,13 +141,19 @@ public CartEidtRes editCart(CustomUserDetails userDetails, Long idx, Long count) return orderMapper.cartToCartEditRes(cartItem); } - private void verifyCart(Cart cart) { + private void verifyCart(Cart cart, Long inout) { if (cart.getIsOrdered()) { throw new BusinessLogicException(ExceptionCode.CART_NOT_EDITABLE); } if (cart.getIsDeleted()) { throw new BusinessLogicException(ExceptionCode.CART_NOT_EDITABLE); } + if (inout == null) { + return; + } + if (!cart.getInOut().equals(inout)) { + throw new BusinessLogicException(ExceptionCode.CART_INOUT_NOT_MATCH); + } } @Override