using System; using System.Collections.Generic; using IRaCIS.Api.Filter; using IRaCIS.Application.Interfaces; using IRaCIS.Application.ViewModels; using IRaCIS.Core.Application.Contracts.RequestAndResponse; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Api.Controllers { [Route("role")] [ApiController, Authorize, ApiExplorerSettings(GroupName = "Management")] public class RoleController : ControllerBase { private readonly IRoleService _roleService; public RoleController(IRoleService roleService) { _roleService = roleService; } /// 添加角色 [HttpPost, Route("addOrUpdateRole")] [LogFilter] public IResponseOutput AddOrUpdateRole(RoleCommand role) { var userId = Guid.Parse(User.FindFirst("id").Value); return _roleService.AddOrUpdateRole(role, userId); } ///// 复制角色 //[HttpPost, Route("copyRole/{sourceRoleId:guid}")] //public IResponseOutput CopyRole(Guid sourceRoleId, RoleAddOrUpdateModel role) //{ // return _roleService.CopyRole(sourceRoleId,role); //} /// 删除角色 [HttpDelete, Route("deleteRole/{roleId:guid}")] [LogFilter] public IResponseOutput DeleteRole(Guid roleId) { return _roleService.DeleteRole(roleId); } /// 分页获取角色列表 [HttpGet, Route("getRoleList/{pageIndex:int}/{pageSize:int}")] public IResponseOutput> GetRoleListByPage(int pageIndex, int pageSize) { return ResponseOutput.Ok(_roleService.GetRoleListByPage(pageIndex, pageSize)); } /// 获取用户角色列表 [HttpGet, Route("getRoleList/{userId:guid}/{pageIndex:int}/{pageSize:int}")] public IResponseOutput> GetRoleListByPage(Guid userId, int pageIndex, int pageSize) { return ResponseOutput.Ok(_roleService.GetRoleListByPage(userId, pageIndex, pageSize)); } /// 更新用户角色 [HttpPost, Route("UpdateUserRole")] [LogFilter] public IResponseOutput UpdateUserRole(UserRoleSelectDTO userSelectRoleModel) { return _roleService.UpdateUserRole(userSelectRoleModel.userId, userSelectRoleModel.roleId, userSelectRoleModel.isSelect); } } }