Skip to content

Commit

Permalink
feat: cart delete api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Jul 22, 2024
1 parent 47bff53 commit c49ce43
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.likelion.coremodule.user.application.UserQueryService;
import com.likelion.coremodule.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class CartSaveUseCase {

private final CartQueryService cartQueryService;
Expand All @@ -31,4 +32,12 @@ public void saveMyCart(String accessToken, CartSaveReq saveReq) {
final Cart cart = Cart.builder().user(user).menu(menu).quantity(saveReq.quantity()).build();
cartQueryService.saveCart(cart);
}

public void deleteMyCart(String accessToken, Long cartId) {

String email = jwtUtil.getEmail(accessToken);
User user = userQueryService.findByEmail(email);

cartQueryService.deleteCartByUserIdAndCartId(user.getUserId(), cartId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@ public ApplicationResponse<String> saveMyCart(@RequestHeader(AuthConsts.ACCESS_T
}

// 장바구니 삭제
@DeleteMapping("{cartId}/delete")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "나의 장바구니 삭제 성공",
useReturnTypeSchema = true
)
}
)
@Operation(summary = "나의 장바구니 삭제 API", description = "나의 장바구니 삭제 API 입니다.")
public ApplicationResponse<String> deleteMyCart(@RequestHeader(AuthConsts.ACCESS_TOKEN_HEADER) String accessToken,
@PathVariable Long cartId) {

cartSaveUseCase.deleteMyCart(accessToken, cartId);
return ApplicationResponse.ok("장바구니 삭제 완료");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface CartRepository extends JpaRepository<Cart, Long> {

List<Cart> findCartsByUserUserId(Long userId);

void deleteCartByIdAndUserUserId(Long cartId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public void saveCart(Cart cart) {
public List<Cart> findCartsByUserId(Long userId) {
return cartRepository.findCartsByUserUserId(userId);
}

public void deleteCartByUserIdAndCartId(Long userId, Long cartId) {

cartRepository.deleteCartByIdAndUserUserId(cartId, userId);
}
}

0 comments on commit c49ce43

Please sign in to comment.