package cn.lihongjie.coal.role.controller;

import cn.lihongjie.coal.annotation.OrgScope;
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.role.dto.CreateRoleDto;
import cn.lihongjie.coal.role.dto.RoleDto;
import cn.lihongjie.coal.role.dto.UpdateRoleDto;
import cn.lihongjie.coal.role.service.RoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
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;

@RequestMapping("/role")
@RestController
@SysLog(module = "角色管理")
@OrgScope
@Transactional
public class RoleController extends BaseController {

    @Autowired RoleService service;

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

    @PostMapping("/update")
    @SysLog(action = "编辑")
    public RoleDto update(@RequestBody UpdateRoleDto 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<RoleDto> list(@RequestBody CommonQuery dto) {
        return this.service.list(dto);
    }

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