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) 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()); } 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(); + } }