package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.CpAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.CpListParam;
import com.zanxiang.game.module.manage.pojo.vo.CpVO;
import com.zanxiang.game.module.manage.service.ICpService;
import com.zanxiang.module.util.pojo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : lingfeng
 * @time : 2022-06-22
 * @description : cp管理接口
 */
@RestController
@RequestMapping("/cp")
@Slf4j
public class CpController {

    @Autowired
    private ICpService cpService;

    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:cp:addOrUpdate")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody CpAddUpdateParam param) {
        return ResultVO.ok(cpService.addOrUpdate(param));
    }

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:cp:list")
    public ResultVO<IPage<CpVO>> list(@Validated @RequestBody CpListParam param) {
        return ResultVO.ok(cpService.list(param));
    }

    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:cp:delete")
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(cpService.deleteById(id));
    }
}
