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.Relic;
import com.amms.service.IRelicService;

import java.util.List;

/**
 * 藏品Controller
 */
@RestController
@RequestMapping("/relic")
public class RelicController {

    @Autowired
    private IRelicService relicService;

    /**
     * 查询藏品列表
     */
    @GetMapping("/list")
    public PageInfo list(Relic relic, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Relic> relics = relicService.selectRelicList(relic);
        return new PageInfo(relics);
    }

    /**
     * 查询全部藏品列表
     */
    @GetMapping("/listAll")
    public List<Relic> listAll(Relic relic) {
        return relicService.selectRelicList(relic);
    }

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

    /**
     * 新增藏品
     */
    @PostMapping("/add")
    public Result add(@RequestBody Relic relic) {
        return relicService.insertRelic(relic) > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 修改藏品
     */
    @PutMapping
    public Result update(@RequestBody Relic relic) {
        return relicService.updateRelic(relic) > 0 ? Result.success("修改成功") : Result.error("修改失败");
    }

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