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.ItemCollection;
import com.amms.service.IItemCollectionService;

import java.util.List;

/**
 * 收藏Controller
 */
@RestController
@RequestMapping("/itemCollection")
public class ItemCollectionController {

    @Autowired
    private IItemCollectionService itemCollectionService;

    /**
     * 查询收藏列表
     */
    @GetMapping("/list")
    public PageInfo list(ItemCollection itemCollection, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ItemCollection> itemCollections = itemCollectionService.selectItemCollectionList(itemCollection);
        return new PageInfo(itemCollections);
    }

    /**
     * 查询全部收藏列表
     */
    @GetMapping("/listAll")
    public List<ItemCollection> listAll(ItemCollection itemCollection) {
        return itemCollectionService.selectItemCollectionList(itemCollection);
    }

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

    /**
     * 新增收藏
     */
    @PostMapping("/add")
    public Result add(@RequestBody ItemCollection itemCollection) {
        return itemCollectionService.insertItemCollection(itemCollection) > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 修改收藏
     */
    @PutMapping
    public Result update(@RequestBody ItemCollection itemCollection) {
        return itemCollectionService.updateItemCollection(itemCollection) > 0 ? Result.success("修改成功") : Result.error("修改失败");
    }

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