引入minimal api 测试
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2024-10-14 14:48:18 +08:00
parent c9a6f8b99b
commit fad9428656
6 changed files with 91 additions and 8 deletions

View File

@ -1,6 +1,7 @@
using IRaCIS.Core.API;
using IRaCIS.Core.Application.BusinessFilter;
using IRaCIS.Core.Application.Filter;
using IRaCIS.Core.Application.MassTransit.Consumer;
using IRaCIS.Core.Application.Service.BackGroundJob;
using IRaCIS.Core.Infra.EFCore;
using IRaCIS.Core.Infrastructure.Extention;
@ -16,7 +17,9 @@ using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
@ -127,6 +130,25 @@ builder.Services.AddDicomSetup();
// 实时应用
builder.Services.AddSignalR();
//MinimalAPI
builder.Services.AddMasaMinimalAPIs(options =>
{
options.Prefix = "";//自定义前缀 默认是api
options.Version = ""; //默认是V1
options.AutoAppendId = false; //路由是否自动附加参数Id 默认是true
options.PluralizeServiceName = false; //服务名称是否启用复数
//options.Assemblies = new List<Assembly>() { typeof(UserSiteSurveySubmitedEventConsumer).Assembly };
options.GetPrefixes = new List<string> { "Get", "Select", "Find" };
options.PostPrefixes = new List<string> { "Post", "Add", "Create" };
options.PutPrefixes = new List<string> { "Put", /*"Update"*/ };
options.DeletePrefixes = new List<string> { "Delete", "Remove" };
options.DisableAutoMapRoute = false;//可通过配置true禁用全局自动路由映射或者删除此配置以启用全局自动路由映射
});
#endregion
var app = builder.Build();
@ -134,6 +156,8 @@ var env = app.Environment;
#region 配置中间件
app.UseMiddleware<EncryptionRequestMiddleware>();
#region 异常处理 全局业务异常已统一处理了,非业务错误会来到这里 400 -500状态码
@ -233,6 +257,13 @@ app.MapControllers();
app.MapHub<UploadHub>("/UploadHub");
app.MapHealthChecks("/health");
#endregion
//Map MinimalAPI routes
app.MapMasaMinimalAPIs();
// Serilog
SerilogExtension.AddSerilogSetup(enviromentName, app.Services);
@ -240,8 +271,6 @@ var hangfireJobService = app.Services.GetRequiredService<IIRaCISHangfireJob>();
await hangfireJobService.InitHangfireJobTaskAsync();
#endregion
try
{
#region 运行环境 部署平台

View File

@ -36,6 +36,8 @@ namespace IRaCIS.Core.API
options.SwaggerDoc("Image", new OpenApiInfo { Title = "影像模块", Version = "Image" });
options.SwaggerDoc("Reading", new OpenApiInfo { Title = "读片模块", Version = "Reading" });
// Add "General" fallback group for ungrouped APIs
//options.SwaggerDoc("General", new OpenApiInfo { Title = "未分类模块", Version = "General" });
// 接口排序
options.OrderActionsBy(o => o.GroupName);
@ -47,6 +49,7 @@ namespace IRaCIS.Core.API
.OfType<ApiExplorerSettingsAttribute>()
.Select(attr => attr.GroupName);
//return versions.Any(v => v == docName) || (docName == "General" && !versions.Any());
return versions.Any(v => v.ToString() == docName);
});

View File

@ -59,6 +59,8 @@
<PackageReference Include="fo-dicom.Codecs" Version="5.14.5" />
<PackageReference Include="IP2Region.Net" Version="2.0.2" />
<PackageReference Include="MailKit" Version="4.7.1.1" />
<PackageReference Include="Masa.Contrib.Service.MinimalAPIs" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
<PackageReference Include="MimeKit" Version="4.7.1" />
<PackageReference Include="MiniExcel" Version="1.34.1" />
<PackageReference Include="Minio" Version="6.0.3" />

View File

@ -12646,6 +12646,11 @@
<param name="outEnrollTime"></param>
<returns></returns>
</member>
<member name="T:IRaCIS.Core.Application.Service.TestMinimalApiService">
<summary>
minimal api 测试
</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>
清理一致性分析任务

View File

@ -14,6 +14,7 @@ using MassTransit;
using MassTransit.Mediator;
using Medallion.Threading;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
@ -30,6 +31,48 @@ using Tea;
namespace IRaCIS.Core.Application.Service
{
/// <summary>
/// minimal api 测试
/// </summary>
[ApiExplorerSettings(GroupName = "Institution")]
public class TestMinimalApiService : ServiceBase
{
public TestMinimalApiService()
{
RouteHandlerBuilder = t => {
t.WithGroupName("TestMinimalApi").WithOpenApi();
};
}
[RoutePattern(HttpMethod = "post")]
public Task<List<string>> GetProjectList1Async()
{
var list = new List<string>()
{
"Auth",
"DCC",
"PM"
};
return Task.FromResult(list);
}
public List<string> GetProjectList()
{
var list = new List<string>()
{
"Auth",
"DCC",
"PM"
};
return list;
}
}
[ApiExplorerSettings(GroupName = "Institution")]
public class TestService(IRepository<Dictionary> _dicRepository,
IRepository<Trial> _trialRepository,
@ -126,7 +169,7 @@ namespace IRaCIS.Core.Application.Service
}
public async Task<IResponseOutput> TestJson()
{

View File

@ -11,11 +11,12 @@ namespace IRaCIS.Core.Infrastructure.Extention
{
// 扩展 string 类型
public static bool IsNullOrEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
//// 扩展 string 类型
//public static bool IsNullOrEmpty(this string value)
//{
// return string.IsNullOrEmpty(value);
//}
public static bool IsNotNullOrEmpty(this string value)
{
return !string.IsNullOrEmpty(value);