diff --git a/spzx-service/service-cart/src/main/java/com/atguigu/cart/controller/CartController.java b/spzx-service/service-cart/src/main/java/com/atguigu/cart/controller/CartController.java index d217a27..2dd5e43 100644 --- a/spzx-service/service-cart/src/main/java/com/atguigu/cart/controller/CartController.java +++ b/spzx-service/service-cart/src/main/java/com/atguigu/cart/controller/CartController.java @@ -8,10 +8,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -36,4 +33,19 @@ public class CartController { List cartInfoList = cartService.getCartList(); return Result.build(cartInfoList, ResultCodeEnum.SUCCESS); } + + @Operation(summary = "删除购物车商品") + @DeleteMapping("auth/deleteCart/{skuId}") + public Result deleteCart(@Parameter(name = "skuId", description = "商品skuId", required = true) @PathVariable("skuId") Long skuId) { + cartService.deleteCart(skuId); + return Result.success(); + } + + @Operation(summary = "更新购物车商品选中状态") + @GetMapping("/auth/checkCart/{skuId}/{isChecked}") + public Result checkCart(@Parameter(name = "skuId", description = "商品skuId", required = true) @PathVariable(value = "skuId") Long skuId, + @Parameter(name = "isChecked", description = "是否选中 1:选中 0:取消选中", required = true) @PathVariable(value = "isChecked") Integer isChecked) { + cartService.checkCart(skuId, isChecked); + return Result.build(null, ResultCodeEnum.SUCCESS); + } } \ No newline at end of file diff --git a/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/CartService.java b/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/CartService.java index e572a18..1a422fe 100644 --- a/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/CartService.java +++ b/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/CartService.java @@ -19,4 +19,11 @@ public interface CartService { * @return 购物车列表 */ List getCartList(); + + /** + * 删除购物车商品 + * + * @param skuId 商品的ID值 + */ + void deleteCart(Long skuId); } diff --git a/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/impl/CartServiceImpl.java b/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/impl/CartServiceImpl.java index ab84d51..6ee2bf1 100644 --- a/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/impl/CartServiceImpl.java +++ b/spzx-service/service-cart/src/main/java/com/atguigu/cart/service/impl/CartServiceImpl.java @@ -88,4 +88,19 @@ public class CartServiceImpl implements CartService { return new ArrayList<>(); } + + /** + * 删除购物车商品 + * + * @param skuId 商品的ID值 + */ + @Override + public void deleteCart(Long skuId) { + // 获取当前登录的用户数据 + Long userId = BaseContext.getUserInfo().getId(); + String cartKey = userId.toString(); + + // 获取缓存对象 + redisTemplate.opsForHash().delete(cartKey, String.valueOf(skuId)); + } }