package com.caimei.www.controller.unlimited;

import com.caimei.www.controller.BaseController;
import com.caimei.www.pojo.page.ProductDetail;
import com.caimei.www.service.page.ProductService;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 商品（product）
 *
 * @author : Charles
 * @date : 2020/6/12
 */
@Controller
public class ProductController extends BaseController {

	private static final String PRODUCT_LIST_PATH = "product/list";
	private static final String PRODUCT_DETAIL_PATH = "product/detail";
	private static final String PROMOTIONS_LIST_PATH = "product/promotions";

    private ProductService productService;
    @Autowired
    public void setProductService(ProductService productService) {
        this.productService = productService;
    }

    /**
     * 商品分类列表/搜索结果 页面
     */
    @GetMapping("/product/list.html")
    public String list() {
        return PRODUCT_LIST_PATH;
    }

    /**
     * 促销活动商品列表
     */
    @GetMapping("/product/promotions.html")
    public String promotions() {
        return PROMOTIONS_LIST_PATH;
    }

    /**
     * 商品详情页
     */
    @GetMapping("/product-{id}.html")
    public String detail(final Model model, @PathVariable("id") Integer productId) {
        ProductDetail detail = productService.getProductDetailById(productId);
        model.addAttribute("productId", productId);
        model.addAttribute("product", detail);
        return PRODUCT_DETAIL_PATH;
    }

}
