Skip to content

Commit

Permalink
Merge pull request #25 from marinesnow34/cartDel
Browse files Browse the repository at this point in the history
Feat: 장바구니 아이템 삭제 구현
  • Loading branch information
marinesnow34 authored Nov 17, 2023
2 parents 29db2cc + ce6d691 commit 6612270
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -49,4 +52,11 @@ public ResponseEntity<CartEidtRes> updateCart(@AuthenticationPrincipal CustomUse
CartEidtRes cartEditRes = orderService.editCart(userDetails, cartEditReq);
return new ResponseEntity<>(cartEditRes, HttpStatus.OK);
}

@DeleteMapping("/cart")
public ResponseEntity<CartItemDeleteRes> deleteCartItem(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody CartItemDeleteReq cartItemDeleteReq) {
CartItemDeleteRes cartItemDeleteRes = orderService.deleteCart(userDetails, cartItemDeleteReq);
return new ResponseEntity<>(cartItemDeleteRes, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.readyvery.readyverydemo.src.order.dto;

import lombok.Getter;

@Getter
public class CartItemDeleteReq {
private Long idx;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 6612270

Please sign in to comment.