新增获取角色列表接口

This commit is contained in:
南浔
2024-12-09 09:58:28 +08:00
3 changed files with 23 additions and 0 deletions
@@ -1,5 +1,6 @@
using Apimanager_backend.Dtos;
using Apimanager_backend.Exceptions;
using Apimanager_backend.Models;
using Apimanager_backend.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -145,5 +146,15 @@ namespace Apimanager_backend.Controllers
return Ok(res);
}
#endregion
#region
[HttpGet]
[Authorize(Roles = "Admin")]
public async Task<ActionResult<ResponseBase<List<UserRole>>>> GetRoles()
{
var userRoles = await adminService.GetRolesAsync();
var res = new ResponseBase<List<UserRole>>(userRoles);
return Ok(res);
}
#endregion
}
}
@@ -114,5 +114,11 @@ namespace Apimanager_backend.Services
return await context.Users.CountAsync();
}
#endregion
#region
public async Task<List<UserRole>> GetRolesAsync()
{
return await context.UserRoles.Where(x => true).Take(10).ToListAsync();
}
#endregion
}
}
@@ -1,4 +1,5 @@
using Apimanager_backend.Dtos;
using Apimanager_backend.Models;
namespace Apimanager_backend.Services
{
@@ -46,5 +47,10 @@ namespace Apimanager_backend.Services
/// </summary>
/// <returns></returns>
Task<int> UserCountAsync();
/// <summary>
/// 获取角色列表
/// </summary>
/// <returns></returns>
Task<List<UserRole>> GetRolesAsync();
}
}