feat(新增): 删除购物车商品
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
c92f246341
commit
cd1b13900e
|
@ -8,10 +8,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -36,4 +33,19 @@ public class CartController {
|
||||||
List<CartInfo> cartInfoList = cartService.getCartList();
|
List<CartInfo> cartInfoList = cartService.getCartList();
|
||||||
return Result.build(cartInfoList, ResultCodeEnum.SUCCESS);
|
return Result.build(cartInfoList, ResultCodeEnum.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除购物车商品")
|
||||||
|
@DeleteMapping("auth/deleteCart/{skuId}")
|
||||||
|
public Result<String> 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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,4 +19,11 @@ public interface CartService {
|
||||||
* @return 购物车列表
|
* @return 购物车列表
|
||||||
*/
|
*/
|
||||||
List<CartInfo> getCartList();
|
List<CartInfo> getCartList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车商品
|
||||||
|
*
|
||||||
|
* @param skuId 商品的ID值
|
||||||
|
*/
|
||||||
|
void deleteCart(Long skuId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,4 +88,19 @@ public class CartServiceImpl implements CartService {
|
||||||
|
|
||||||
return new ArrayList<>();
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue