package cn.lihongjie.coal.permission.controller;

import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.controller.BaseController;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.permission.dto.*;
import cn.lihongjie.coal.permission.service.PermissionService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/permission")
@RestController
@SysLog(module = "权限管理")
public class PermissionController extends BaseController {

    @Autowired PermissionService service;

    @PostMapping("/create")
    @SysLog(action = "新增")
    public PermissionDto create(@RequestBody CreatePermissionDto dto) {
        return this.service.create(dto);
    }

    @PostMapping("/update")
    @SysLog(action = "编辑")
    public PermissionDto update(@RequestBody UpdatePermissionDto dto) {
        return this.service.update(dto);
    }

    @PostMapping("/delete")
    @SysLog(action = "删除")
    public Object delete(@RequestBody IdRequest dto) {
        this.service.delete(dto);
        return true;
    }

    @PostMapping("/list")
    public Page<PermissionDto> list(@RequestBody CommonQuery dto) {
        return this.service.list(dto);
    }

    @PostMapping("/getById")
    public PermissionDto getById(@RequestBody IdRequest dto) {
        return this.service.getById(dto.getId());
    }

    @PostMapping("/exportAll")
    public List<PermissionExportDto> exportAll(@RequestBody CommonQuery dto) {
        return this.service.exportAll();
    }

    @PostMapping("/importAll")
    public Boolean getById(@RequestBody PermissionImportDto dto) {
        this.service.importAll(dto);
        return true;
    }
}
