show the shopping cart of current user
This commit is contained in:
@@ -1,16 +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.beans.factory.annotation.Autowired;
|
||||
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 java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/shoppingCart")
|
||||
@@ -35,4 +35,15 @@ public class ShoppingCartController {
|
||||
shoppingCartService.addIntoShoppingCart(shoppingCartDTO);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface ShoppingCartService {
|
||||
|
||||
@@ -13,4 +16,10 @@ public interface ShoppingCartService {
|
||||
* It includes dishId, setmealId, and dishFlavor necessary for identifying and customizing the item.
|
||||
*/
|
||||
void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||
|
||||
/**
|
||||
* list shopping cart of current user
|
||||
* @return
|
||||
*/
|
||||
List<ShoppingCart> listShoppingCart();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -71,4 +72,16 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
shoppingCartMapper.insert(shoppingCart);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list shopping cart
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ShoppingCart> listShoppingCart() {
|
||||
ShoppingCart shoppingCart = ShoppingCart.builder()
|
||||
.userId(BaseContext.getCurrentId())
|
||||
.build();
|
||||
return shoppingCartMapper.list(shoppingCart);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user