minimal api 测试准备
parent
a3ec9618ed
commit
67e09bbf66
|
@ -2,7 +2,9 @@
|
||||||
using IRaCIS.Core.Application.BusinessFilter;
|
using IRaCIS.Core.Application.BusinessFilter;
|
||||||
using IRaCIS.Core.Application.Filter;
|
using IRaCIS.Core.Application.Filter;
|
||||||
using IRaCIS.Core.Application.MassTransit.Consumer;
|
using IRaCIS.Core.Application.MassTransit.Consumer;
|
||||||
|
using IRaCIS.Core.Application.Service;
|
||||||
using IRaCIS.Core.Application.Service.BackGroundJob;
|
using IRaCIS.Core.Application.Service.BackGroundJob;
|
||||||
|
using IRaCIS.Core.Application.Service.BusinessFilter;
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
using IRaCIS.Core.Infra.EFCore;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
using LogDashboard;
|
using LogDashboard;
|
||||||
|
@ -11,6 +13,7 @@ using MassTransit.NewIdProviders;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
@ -92,7 +95,6 @@ builder.Services.AddControllers(options =>
|
||||||
options.Filters.Add<ModelActionFilter>();
|
options.Filters.Add<ModelActionFilter>();
|
||||||
options.Filters.Add<ProjectExceptionFilter>();
|
options.Filters.Add<ProjectExceptionFilter>();
|
||||||
options.Filters.Add<UnitOfWorkFilter>();
|
options.Filters.Add<UnitOfWorkFilter>();
|
||||||
//options.Filters.Add<EncreptApiResultFilter>(10);
|
|
||||||
options.Filters.Add<LimitUserRequestAuthorization>();
|
options.Filters.Add<LimitUserRequestAuthorization>();
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,11 +143,14 @@ builder.Services.AddMasaMinimalAPIs(options =>
|
||||||
//options.Assemblies = new List<Assembly>() { typeof(UserSiteSurveySubmitedEventConsumer).Assembly };
|
//options.Assemblies = new List<Assembly>() { typeof(UserSiteSurveySubmitedEventConsumer).Assembly };
|
||||||
|
|
||||||
options.GetPrefixes = new List<string> { "Get", "Select", "Find" };
|
options.GetPrefixes = new List<string> { "Get", "Select", "Find" };
|
||||||
options.PostPrefixes = new List<string> { "Post", "Add", "Create" };
|
options.PostPrefixes = new List<string> { "Post", "Add", "Create", "List" };
|
||||||
options.PutPrefixes = new List<string> { "Put", /*"Update"*/ };
|
options.PutPrefixes = new List<string> { "Put", "Update" };
|
||||||
options.DeletePrefixes = new List<string> { "Delete", "Remove" };
|
options.DeletePrefixes = new List<string> { "Delete", "Remove" };
|
||||||
|
|
||||||
|
options.RouteHandlerBuilder= t=> {
|
||||||
|
t.RequireAuthorization().AddEndpointFilter<UnifiedApiResultEndpointFilter>();
|
||||||
|
};
|
||||||
|
options.DisableTrimMethodPrefix = true; //禁用去除方法前缀
|
||||||
options.DisableAutoMapRoute = false;//可通过配置true禁用全局自动路由映射或者删除此配置以启用全局自动路由映射
|
options.DisableAutoMapRoute = false;//可通过配置true禁用全局自动路由映射或者删除此配置以启用全局自动路由映射
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,23 @@
|
||||||
using IRaCIS.Core.Application.Service.BusinessFilter;
|
using IRaCIS.Core.Application.Service.BusinessFilter;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
using Panda.DynamicWebApi;
|
using Panda.DynamicWebApi;
|
||||||
using Panda.DynamicWebApi.Attributes;
|
using Panda.DynamicWebApi.Attributes;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service;
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS8618
|
|
||||||
|
|
||||||
|
|
||||||
#region 非泛型版本
|
|
||||||
|
|
||||||
[TypeFilter(typeof(UnifiedApiResultFilter))]
|
[TypeFilter(typeof(UnifiedApiResultFilter))]
|
||||||
[Authorize, DynamicWebApi]
|
[Authorize, DynamicWebApi]
|
||||||
public class BaseService : IBaseService, IDynamicWebApi
|
public class BaseService : IDynamicWebApi
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,13 +29,3 @@ namespace IRaCIS.Core.Application.Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface IBaseService
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service.BusinessFilter;
|
namespace IRaCIS.Core.Application.Service.BusinessFilter;
|
||||||
|
|
||||||
|
|
||||||
|
#region 控制器流程
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
/// 统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
||||||
/// by zhouhang 2021.09.12 周末
|
/// by zhouhang 2021.09.12 周末
|
||||||
|
@ -120,3 +123,59 @@ public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region minimalapi 流程
|
||||||
|
|
||||||
|
|
||||||
|
public class UnifiedApiResultEndpointFilter : IEndpointFilter
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public UnifiedApiResultEndpointFilter(ILogger<UnifiedApiResultFilter> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
|
||||||
|
{
|
||||||
|
// 调用下一个过滤器或端点处理程序
|
||||||
|
var result = await next(context);
|
||||||
|
|
||||||
|
// 检查返回值类型
|
||||||
|
if (result is null)
|
||||||
|
{
|
||||||
|
return ResponseOutput.NotOk("No data found."); // 处理 null 返回
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果返回的是元组
|
||||||
|
if (result is ValueTuple<object, object> tuple)
|
||||||
|
{
|
||||||
|
return ResponseOutput.Ok(tuple.Item1, tuple.Item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result is IResponseOutput)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对于其他情况,直接返回结果
|
||||||
|
return ResponseOutput.Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IResponseOutput WrapResponse(object? value)
|
||||||
|
{
|
||||||
|
// 处理元组的情况
|
||||||
|
if (value is ValueTuple<object, object> tuple)
|
||||||
|
{
|
||||||
|
return ResponseOutput.Ok(tuple.Item1, tuple.Item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 包装单个对象
|
||||||
|
return ResponseOutput.Ok(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -9532,6 +9532,16 @@
|
||||||
|
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.ReadingQuestionTrialView.ExportIdentification">
|
||||||
|
<summary>
|
||||||
|
导出标识
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.ReadingQuestionTrialView.ExportResult">
|
||||||
|
<summary>
|
||||||
|
导出结果
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.ReadingQuestionTrialView.GroupName">
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.ReadingQuestionTrialView.GroupName">
|
||||||
<summary>
|
<summary>
|
||||||
分组
|
分组
|
||||||
|
@ -10132,6 +10142,16 @@
|
||||||
图片数量
|
图片数量
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionSystemInDto.ExportIdentification">
|
||||||
|
<summary>
|
||||||
|
导出标识
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionSystemInDto.ExportResult">
|
||||||
|
<summary>
|
||||||
|
导出结果
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionSystemInDto.ValueType">
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionSystemInDto.ValueType">
|
||||||
<summary>
|
<summary>
|
||||||
数值类型
|
数值类型
|
||||||
|
@ -10327,6 +10347,16 @@
|
||||||
Id
|
Id
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionTrialInDto.ExportIdentification">
|
||||||
|
<summary>
|
||||||
|
导出标识
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionTrialInDto.ExportResult">
|
||||||
|
<summary>
|
||||||
|
导出结果
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionTrialInDto.HighlightAnswer">
|
<member name="P:IRaCIS.Core.Application.Service.Reading.Dto.AddOrUpdateReadingQuestionTrialInDto.HighlightAnswer">
|
||||||
<summary>
|
<summary>
|
||||||
高亮问题的答案
|
高亮问题的答案
|
||||||
|
|
|
@ -3,6 +3,7 @@ using IRaCIS.Application.Contracts;
|
||||||
using IRaCIS.Core.Application.BusinessFilter;
|
using IRaCIS.Core.Application.BusinessFilter;
|
||||||
using IRaCIS.Core.Application.Contracts;
|
using IRaCIS.Core.Application.Contracts;
|
||||||
using IRaCIS.Core.Application.Helper;
|
using IRaCIS.Core.Application.Helper;
|
||||||
|
using IRaCIS.Core.Application.Service.BusinessFilter;
|
||||||
using IRaCIS.Core.Application.ViewModel;
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Domain;
|
using IRaCIS.Core.Domain;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
@ -34,18 +35,22 @@ namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// minimal api 测试
|
/// minimal api 测试
|
||||||
|
/// 学习参考文档:http://fanrk.cn/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/MinimalApi/MinimalApi.html
|
||||||
|
/// 组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiExplorerSettings(GroupName = "Institution")]
|
[ApiExplorerSettings(GroupName = "Institution")]
|
||||||
|
|
||||||
public class TestMinimalApiService : ServiceBase
|
public class TestMinimalApiService : ServiceBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public TestMinimalApiService()
|
public TestMinimalApiService()
|
||||||
{
|
{
|
||||||
RouteHandlerBuilder = t => {
|
RouteHandlerBuilder = t =>
|
||||||
t.WithOpenApi();
|
{
|
||||||
|
t.RequireAuthorization().WithGroupName("Institution").AddEndpointFilter<UnifiedApiResultEndpointFilter>();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[RoutePattern(HttpMethod = "post")]
|
|
||||||
public Task<List<string>> GetProjectList1Async()
|
public Task<List<string>> GetProjectList1Async()
|
||||||
{
|
{
|
||||||
var list = new List<string>()
|
var list = new List<string>()
|
||||||
|
@ -56,17 +61,6 @@ namespace IRaCIS.Core.Application.Service
|
||||||
};
|
};
|
||||||
return Task.FromResult(list);
|
return Task.FromResult(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GetProjectList()
|
|
||||||
{
|
|
||||||
var list = new List<string>()
|
|
||||||
{
|
|
||||||
"Auth",
|
|
||||||
"DCC",
|
|
||||||
"PM"
|
|
||||||
};
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue