查看购物车业务代码开发

This commit is contained in:
zvv
2026-04-02 17:07:15 +08:00
parent c65e4860f8
commit 689ce56914
3 changed files with 41 additions and 4 deletions

View File

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

View File

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

View File

@@ -81,4 +81,19 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
} }
} }
/**
*查看购物车
* @return
*/
@Override
public List<ShoppingCart> showShoppingCart() {
//获取当前微信用户的id
Long userId = BaseContext.getCurrentId();
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.setUserId(userId);
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
return list;
}
} }