package com.example.controller;

import com.example.common.Result;
import com.example.entity.Productype;
import com.example.service.ProductypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 前端操作接口
 **/
@RestController
@RequestMapping("/productype")
public class ProductypeController {

    @Resource
    private ProductypeService productypeService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Productype productype) {
        productypeService.add(productype);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        productypeService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        productypeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Productype productype) {
        productypeService.updateById(productype);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Productype productype = productypeService.selectById(id);
        return Result.success(productype);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Productype productype) {
        List<Productype> list = productypeService.selectAll(productype);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Productype productype,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Productype> page = productypeService.selectPage(productype, pageNum, pageSize);
        return Result.success(page);
    }

}