查看购物车

This commit is contained in:
bunny 2024-01-09 20:09:40 +08:00
parent f46e752a40
commit f84dca1f1c
3 changed files with 39 additions and 4 deletions

View File

@ -1,17 +1,16 @@
package com.sky.controller.user;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/user/shoppingCart")
@ -35,4 +34,16 @@ public class ShoppingCartController {
shoppingCartService.addShoppingCart(shoppingCartDTO);
return Result.success();
}
/**
* 查看购物车
*
* @return 购物车集合
*/
@ApiOperation("查看购物车")
@GetMapping("/list")
public Result<List<ShoppingCart>> list() {
List<ShoppingCart> list = shoppingCartService.showShoppingCart();
return Result.success(list);
}
}

View File

@ -1,6 +1,9 @@
package com.sky.service;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import java.util.List;
public interface ShoppingCartService {
/**
@ -9,4 +12,12 @@ public interface ShoppingCartService {
* @param shoppingCartDTO 购物车参数
*/
void addShoppingCart(ShoppingCartDTO shoppingCartDTO);
/**
* 查看购物车
*
* @return 购物车集合
*/
List<ShoppingCart> showShoppingCart();
}

View File

@ -69,4 +69,17 @@ public class ShoppingCartServiceImplImpl implements ShoppingCartService {
shoppingCartMapper.insert(shoppingCart);
}
}
/**
* 查看购物车
*
* @return 购物车列表
*/
@Override
public List<ShoppingCart> showShoppingCart() {
// 当前微信用户id
Long currentId = BaseContext.getCurrentId();
ShoppingCart shoppingCart = ShoppingCart.builder().userId(currentId).build();
return shoppingCartMapper.list(shoppingCart);
}
}