show the shopping cart of current user

This commit is contained in:
2024-12-18 22:42:43 +08:00
parent ea8347d6b9
commit 4734a67b59
3 changed files with 37 additions and 4 deletions

View File

@@ -1,16 +1,16 @@
package com.sky.controller.user; 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
@RequestMapping("/user/shoppingCart") @RequestMapping("/user/shoppingCart")
@@ -35,4 +35,15 @@ public class ShoppingCartController {
shoppingCartService.addIntoShoppingCart(shoppingCartDTO); shoppingCartService.addIntoShoppingCart(shoppingCartDTO);
return Result.success(); return Result.success();
} }
/**
* list the shopping cart of current user
* @return
*/
@GetMapping("/list")
@ApiOperation("list shopping cart")
public Result<List<ShoppingCart>> list(){
List<ShoppingCart> list = shoppingCartService.listShoppingCart();
return Result.success(list);
}
} }

View File

@@ -1,8 +1,11 @@
package com.sky.service; package com.sky.service;
import com.sky.dto.ShoppingCartDTO; import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public interface ShoppingCartService { public interface ShoppingCartService {
@@ -13,4 +16,10 @@ public interface ShoppingCartService {
* It includes dishId, setmealId, and dishFlavor necessary for identifying and customizing the item. * It includes dishId, setmealId, and dishFlavor necessary for identifying and customizing the item.
*/ */
void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO); void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO);
/**
* list shopping cart of current user
* @return
*/
List<ShoppingCart> listShoppingCart();
} }

View File

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List; import java.util.List;
@Service @Service
@@ -71,4 +72,16 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
shoppingCartMapper.insert(shoppingCart); shoppingCartMapper.insert(shoppingCart);
} }
} }
/**
* list shopping cart
* @return
*/
@Override
public List<ShoppingCart> listShoppingCart() {
ShoppingCart shoppingCart = ShoppingCart.builder()
.userId(BaseContext.getCurrentId())
.build();
return shoppingCartMapper.list(shoppingCart);
}
} }