package com.fjhx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.Product;
import com.fjhx.service.ProductExService;
import com.fjhx.service.ProductService;
import org.springblade.core.tool.api.R;
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 java.util.Map;

/**
 * 产品 前端控制器
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private ProductExService productExService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, String> condition) {
        Page<Product> result = productExService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody Product product) {
        productService.add(product);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody Product product) {
        productService.edit(product);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody Product product) {
        productService.delete(product);
        return R.success();
    }

    @PostMapping("/list")
    public R list() {
        return R.success(productService.list());
    }

}
