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.MuseumIntro;
import com.amms.service.IMuseumIntroService;

import java.util.List;

/**
 * 博物馆简介Controller
 */
@RestController
@RequestMapping("/museumIntro")
public class MuseumIntroController {

    @Autowired
    private IMuseumIntroService museumIntroService;

    /**
     * 查询博物馆简介列表
     */
    @GetMapping("/list")
    public PageInfo list(MuseumIntro museumIntro, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MuseumIntro> museumIntros = museumIntroService.selectMuseumIntroList(museumIntro);
        return new PageInfo(museumIntros);
    }

    /**
     * 查询全部博物馆简介列表
     */
    @GetMapping("/listAll")
    public List<MuseumIntro> listAll(MuseumIntro museumIntro) {
        return museumIntroService.selectMuseumIntroList(museumIntro);
    }

    /**
     * 获取博物馆简介详细信息
     */
    @GetMapping(value = "/info/{museumName}")
    public Result getInfo(@PathVariable("museumName") String museumName) {
        return Result.success(museumIntroService.selectMuseumIntroByMuseumName(museumName));
    }

    /**
     * 新增博物馆简介
     */
    @PostMapping("/add")
    public Result add(@RequestBody MuseumIntro museumIntro) {
        return museumIntroService.insertMuseumIntro(museumIntro) > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 修改博物馆简介
     */
    @PutMapping
    public Result update(@RequestBody MuseumIntro museumIntro) {
        return museumIntroService.updateMuseumIntro(museumIntro) > 0 ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 删除博物馆简介
     */
	@DeleteMapping("/{museumName}")
    public Result delete(@PathVariable String museumName) {
        return museumIntroService.deleteMuseumIntroByMuseumName(museumName) > 0 ? Result.success("删除成功") : Result.error("删除失败");
    }
}
