package com.amms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.amms.domain.vo.Result;
import com.amms.domain.ItemCategory;
import com.amms.service.IItemCategoryService;

import java.util.List;

/**
 * 藏品分类Controller
 */
@RestController
@RequestMapping("/itemCategory")
public class ItemCategoryController {

    @Autowired
    private IItemCategoryService itemCategoryService;

    /**
     * 查询藏品分类列表
     */
    @GetMapping("/list")
    public PageInfo list(ItemCategory itemCategory, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ItemCategory> itemCategorys = itemCategoryService.selectItemCategoryList(itemCategory);
        return new PageInfo(itemCategorys);
    }

    /**
     * 查询全部藏品分类列表
     */
    @GetMapping("/listAll")
    public List<ItemCategory> listAll(ItemCategory itemCategory) {
        return itemCategoryService.selectItemCategoryList(itemCategory);
    }

    /**
     * 获取藏品分类详细信息
     */
    @GetMapping(value = "/info/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(itemCategoryService.selectItemCategoryById(id));
    }

    /**
     * 新增藏品分类
     */
    @PostMapping("/add")
    public Result add(@RequestBody ItemCategory itemCategory) {
        return itemCategoryService.insertItemCategory(itemCategory) > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 修改藏品分类
     */
    @PutMapping
    public Result update(@RequestBody ItemCategory itemCategory) {
        return itemCategoryService.updateItemCategory(itemCategory) > 0 ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 删除藏品分类
     */
	@DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        return itemCategoryService.deleteItemCategoryById(id) > 0 ? Result.success("删除成功") : Result.error("删除失败");
    }
}
