-51
@@ -126,56 +126,5 @@ public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
|
||||
#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
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service.BusinessFilter;
|
||||
|
||||
#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
|
||||
@@ -12681,6 +12681,13 @@
|
||||
组件参考文档:https://docs.masastack.com/framework/building-blocks/minimal-apis#section-69828ff0
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.TestMinimalApiService.#ctor(IRaCIS.Core.Domain.Share.IUserInfo)">
|
||||
<summary>
|
||||
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>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.TestService.DeleteConsistentDate(System.Guid,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TaskConsistentRule},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingConsistentClinicalDataPDF},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingConsistentClinicalData})">
|
||||
<summary>
|
||||
清理一致性分析任务
|
||||
|
||||
@@ -40,16 +40,10 @@ namespace IRaCIS.Core.Application.Service
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "Institution")]
|
||||
|
||||
public class TestMinimalApiService : ServiceBase
|
||||
public class TestMinimalApiService(IUserInfo _userInfo) : ServiceBase
|
||||
{
|
||||
|
||||
public TestMinimalApiService()
|
||||
{
|
||||
RouteHandlerBuilder = t =>
|
||||
{
|
||||
t.RequireAuthorization().WithGroupName("Institution").AddEndpointFilter<UnifiedApiResultEndpointFilter>();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Task<List<string>> GetProjectList1Async()
|
||||
{
|
||||
@@ -61,6 +55,11 @@ namespace IRaCIS.Core.Application.Service
|
||||
};
|
||||
return Task.FromResult(list);
|
||||
}
|
||||
|
||||
public IResponseOutput GetTest()
|
||||
{
|
||||
return ResponseOutput.Ok(_userInfo.IP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user