权限认证
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
@@ -10,38 +11,45 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
public class BaseCrudController<T> : ControllerBase where T : class,new()
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
|
||||
public IRepository<T> _iRepository;
|
||||
public BaseCrudController(ILogger<T> logger, IRepository<T> iRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_iRepository = iRepository;
|
||||
}
|
||||
|
||||
[Permission($"{nameof(T)}:Get:One")]
|
||||
[HttpGet]
|
||||
public async Task<Result> Get()
|
||||
public async Task<Result> Get(object id)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.GetByIdAsync(id));
|
||||
}
|
||||
[Permission($"{nameof(T)}:Get:List")]
|
||||
[HttpGet]
|
||||
public async Task<Result> GetList()
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.GetListAsync());
|
||||
}
|
||||
|
||||
[Permission($"{nameof(T)}:Get:Page")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Page(QueryCondition queryCondition)
|
||||
public async Task<Result> Page(QueryCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(_iRepository.CommonPage(queryCondition));
|
||||
return Result.Success().SetData(await _iRepository.CommonPage(queryCondition));
|
||||
}
|
||||
|
||||
[Permission($"{nameof(T)}:Add")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(T entity)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.InsertReturnEntityAsync(entity));
|
||||
}
|
||||
[Permission($"{nameof(T)}:Update")]
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(T entity)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRepository.UpdateAsync(entity));
|
||||
}
|
||||
[Permission($"{nameof(T)}:Delete:List")]
|
||||
[HttpDelete]
|
||||
public async Task<Result> Delete(object[] ids)
|
||||
public async Task<Result> DeleteList(object[] ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRepository.DeleteByIdsAsync(ids));
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
@@ -20,12 +21,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
|
||||
{
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Test()
|
||||
[Permission("user:query:list")]
|
||||
public async Task<Result> PermissionTest()
|
||||
{
|
||||
return Ok(await _iRepository.GetListAsync());
|
||||
return Result.Success().SetData( await _iRepository.GetListAsync());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Autofac;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Language;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddCommandLine(args);
|
||||
@@ -48,6 +49,10 @@ builder.Host.ConfigureLogging(loggingBuilder =>
|
||||
#endregion
|
||||
builder.Services.AddIocService(builder.Configuration);
|
||||
#region
|
||||
//Sqlsugar<61><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
builder.Services.AddSqlsugarServer();
|
||||
#region
|
||||
//Quartz<74><7A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddQuartzService();
|
||||
@@ -55,9 +60,13 @@ builder.Services.AddQuartzService();
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddControllers(optios => {
|
||||
//optios.Filters.Add(typeof(CustomExceptionFilterAttribute));
|
||||
//optios.Filters.Add<PermissionAttribute>();
|
||||
}).AddJsonFileService();
|
||||
#region
|
||||
//Ȩ<><EFBFBD><DEB9><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddSingleton<PermissionAttribute>();
|
||||
#region
|
||||
//Swagger<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddSwaggerService<Program>();
|
||||
@@ -92,8 +101,7 @@ builder.Services.AddSMSService();
|
||||
#region
|
||||
//CAP<41><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
builder.Services.AddCAPService<Program>();
|
||||
|
||||
builder.Services.AddCAPService();
|
||||
#region
|
||||
//<2F><><EFBFBD>ʻ<EFBFBD><CABB><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion
|
||||
@@ -119,17 +127,15 @@ ServiceLocator.Instance = app.Services;
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD>ץȡ<D7A5><C8A1><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
//app.UseErrorHandlingService();
|
||||
app.UseErrorHandlingService();
|
||||
#region
|
||||
//<2F><>̬<EFBFBD>ļ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
//app.UseStaticFiles();
|
||||
|
||||
app.UseStaticFiles();
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><D4B9>ʻ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
app.UseLocalizerService();
|
||||
|
||||
#region
|
||||
//HttpsRedirectionע<6E><D7A2>
|
||||
#endregion
|
||||
@@ -161,7 +167,7 @@ app.UseConsulService();
|
||||
#region
|
||||
//redis<69><73><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
app.UseRedisSeedInitService(app.Services.GetService<CacheClientDB>());
|
||||
app.UseRedisSeedInitService();
|
||||
#region
|
||||
//Endpointsע<73><D7A2>
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user