From 05286aab7adbaa9c0c14322884f1c8918b3538c3 Mon Sep 17 00:00:00 2001 From: marinesnow34 Date: Fri, 17 Nov 2023 23:33:18 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Config:=20domain=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/readyvery/readyverydemo/domain/CartItem.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java b/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java index d559dad..ce7de18 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java @@ -51,6 +51,11 @@ public class CartItem extends BaseTimeEntity { @JoinColumn(name = "cart_idx") private Cart cart; + // 장바구니 아이템 삭제 여부 + @Column(columnDefinition = "BOOLEAN default true") + @Builder.Default + private Boolean isDeleted = false; + // 장바구니 아이템 - 장바구니 옵션 연관관계 매핑 @Builder.Default @OneToMany(mappedBy = "cartItem", cascade = CascadeType.ALL) From 54f6b69077a8d417467bcc95c74e1a4dd39ae2b1 Mon Sep 17 00:00:00 2001 From: marinesnow34 Date: Fri, 17 Nov 2023 23:33:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Feat:=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyverydemo/src/order/dto/CartItemDeleteReq.java | 8 ++++++++ .../readyverydemo/src/order/dto/CartItemDeleteRes.java | 10 ++++++++++ .../readyverydemo/src/order/dto/OrderMapper.java | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteReq.java create mode 100644 src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteRes.java diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteReq.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteReq.java new file mode 100644 index 0000000..fc70190 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteReq.java @@ -0,0 +1,8 @@ +package com.readyvery.readyverydemo.src.order.dto; + +import lombok.Getter; + +@Getter +public class CartItemDeleteReq { + private Long idx; +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteRes.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteRes.java new file mode 100644 index 0000000..0823c30 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CartItemDeleteRes.java @@ -0,0 +1,10 @@ +package com.readyvery.readyverydemo.src.order.dto; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CartItemDeleteRes { + private Long idx; +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index 1f34a49..5ffc796 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -70,4 +70,10 @@ public CartEidtRes cartToCartEditRes(CartItem cartItem) { .count(cartItem.getCount()) .build(); } + + public CartItemDeleteRes cartToCartItemDeleteRes(CartItem cartItem) { + return CartItemDeleteRes.builder() + .idx(cartItem.getId()) + .build(); + } } From ce6d6915a7f37f800124e704b52c5cf0e9e8701b Mon Sep 17 00:00:00 2001 From: marinesnow34 Date: Fri, 17 Nov 2023 23:33:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Feat:=20=EC=9E=A5=EB=B0=94=EA=B5=AC?= =?UTF-8?q?=EB=8B=88=20=EC=95=84=EC=9D=B4=ED=85=9C=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/order/OrderController.java | 10 ++++++++++ .../readyverydemo/src/order/OrderService.java | 4 ++++ .../src/order/OrderServiceImpl.java | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java index 18397f3..19bbdc3 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java @@ -3,6 +3,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -17,6 +18,8 @@ import com.readyvery.readyverydemo.src.order.dto.CartAddRes; import com.readyvery.readyverydemo.src.order.dto.CartEditReq; import com.readyvery.readyverydemo.src.order.dto.CartEidtRes; +import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteReq; +import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes; import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes; import lombok.RequiredArgsConstructor; @@ -49,4 +52,11 @@ public ResponseEntity updateCart(@AuthenticationPrincipal CustomUse CartEidtRes cartEditRes = orderService.editCart(userDetails, cartEditReq); return new ResponseEntity<>(cartEditRes, HttpStatus.OK); } + + @DeleteMapping("/cart") + public ResponseEntity deleteCartItem(@AuthenticationPrincipal CustomUserDetails userDetails, + @RequestBody CartItemDeleteReq cartItemDeleteReq) { + CartItemDeleteRes cartItemDeleteRes = orderService.deleteCart(userDetails, cartItemDeleteReq); + return new ResponseEntity<>(cartItemDeleteRes, HttpStatus.OK); + } } diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java index 11229c6..b974c5d 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java @@ -5,6 +5,8 @@ import com.readyvery.readyverydemo.src.order.dto.CartAddRes; import com.readyvery.readyverydemo.src.order.dto.CartEditReq; import com.readyvery.readyverydemo.src.order.dto.CartEidtRes; +import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteReq; +import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes; import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes; public interface OrderService { @@ -13,4 +15,6 @@ public interface OrderService { CartAddRes addCart(CustomUserDetails userDetails, CartAddReq cartAddReq); CartEidtRes editCart(CustomUserDetails userDetails, CartEditReq cartEditReq); + + CartItemDeleteRes deleteCart(CustomUserDetails userDetails, CartItemDeleteReq cartItemDeleteReq); } 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 320586a..832c7cb 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -28,6 +28,8 @@ import com.readyvery.readyverydemo.src.order.dto.CartAddRes; import com.readyvery.readyverydemo.src.order.dto.CartEditReq; import com.readyvery.readyverydemo.src.order.dto.CartEidtRes; +import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteReq; +import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes; import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes; import com.readyvery.readyverydemo.src.order.dto.OrderMapper; @@ -86,6 +88,21 @@ public CartEidtRes editCart(CustomUserDetails userDetails, CartEditReq cartEditR return orderMapper.cartToCartEditRes(cartItem); } + @Override + public CartItemDeleteRes deleteCart(CustomUserDetails userDetails, CartItemDeleteReq cartItemDeleteReq) { + CartItem cartItem = getCartItem(cartItemDeleteReq.getIdx()); + + verifyCartItem(cartItem, userDetails); + + deleteCartItem(cartItem); + cartItemRepository.save(cartItem); + return orderMapper.cartToCartItemDeleteRes(cartItem); + } + + private void deleteCartItem(CartItem cartItem) { + cartItem.setIsDeleted(true); + } + private void editCartItem(CartItem cartItem, CartEditReq cartEditReq) { cartItem.setCount(cartEditReq.getCount()); }