package com.wsk.travelf.controller.backstage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wsk.travelf.pojo.Product;
import com.wsk.travelf.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/backstage/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    //分页查询所有产品信息
    @RequestMapping("/all")
    @PreAuthorize("hasAnyAuthority('/product/all')")
    public ModelAndView all(@RequestParam(defaultValue = "1") int page,
                            @RequestParam(defaultValue = "5") int size) {

        Page<Product> productPage = productService.findAll(page, size);

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("productPage",productPage);
        modelAndView.setViewName("/backstage/product_all");

        return modelAndView;
    }

}
