package com.caimei.www.controller.authorized;

import com.caimei.www.controller.BaseController;
import com.caimei.www.pojo.JsonModel;
import com.caimei.www.pojo.order.CartItem;
import com.caimei.www.service.page.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 购物车
 *
 * @author : Charles
 * @date : 2020/7/23
 */
@Controller
public class ShoppingController extends BaseController {

	private static final String SHOPPING_CART_PATH = "shopping/cart";
	private static final String SHOPPING_CONFIRM_PATH = "shopping/confirm";

    private ShoppingService shoppingService;
    @Autowired
    public void setShoppingService(ShoppingService shoppingService) {
        this.shoppingService = shoppingService;
    }

    /**
     * 购物车列表页
     */
    @GetMapping("/shopping/cart.html")
    public String list() {
        return SHOPPING_CART_PATH;
    }

    /**
     * 确认订单页
     */
    @GetMapping("/shopping/confirm.html")
    public String confirm() {
        return SHOPPING_CONFIRM_PATH;
    }

    /**
     * 顶部购物车数据
     * @return
     */
    @GetMapping("/header/cart")
    @ResponseBody
    public JsonModel<List<CartItem>> getHeadCarts(Integer userId) {
        return shoppingService.getHeaderCart(userId);
    }


}
