feat: 完善统一端点响应与请求绑定框架
- 新增 IApiResponse 统一响应契约,覆盖普通响应和分页响应
- 扩展端点映射,支持 IApiResponse 和带请求 DTO 的 MapXxx 重载
- 增加 Body、Query、Route Values 到请求 DTO 的自动绑定
- 增加 PC 端路由模式匹配,支持 {id} 和 {id:int}
- API 与 PC 端点上下文补充路由参数传递
- 调整 OpenAPI 请求类型处理,避免 GET/DELETE 被标记为 JSON Body
- 鉴权端点迁移到强类型请求绑定和 IApiResponse 返回
- 增加统一端点文件流响应支持
This commit is contained in:
@@ -109,10 +109,19 @@ namespace Avalonia_Services.Extensions
|
||||
Dictionary<string, string>? query = null)
|
||||
{
|
||||
// 查找匹配的端点(忽略大小写 + 方法匹配)
|
||||
var endpoint = _endpoints.Endpoints.FirstOrDefault(e =>
|
||||
e.SupportsHost(EndpointHostTarget.Pc) &&
|
||||
string.Equals(e.Pattern, path, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.Equals(e.HttpMethod, method, StringComparison.OrdinalIgnoreCase));
|
||||
var match = _endpoints.Endpoints
|
||||
.Where(e =>
|
||||
e.SupportsHost(EndpointHostTarget.Pc) &&
|
||||
string.Equals(e.HttpMethod, method, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(e => new
|
||||
{
|
||||
Endpoint = e,
|
||||
IsMatched = ServiceEndpointPatternMatcher.TryMatch(e.Pattern, path, out var routeValues),
|
||||
RouteValues = routeValues,
|
||||
})
|
||||
.FirstOrDefault(candidate => candidate.IsMatched);
|
||||
|
||||
var endpoint = match?.Endpoint;
|
||||
|
||||
if (endpoint is null)
|
||||
{
|
||||
@@ -127,6 +136,7 @@ namespace Avalonia_Services.Extensions
|
||||
Body = body,
|
||||
Headers = headers ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
||||
Query = query ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
||||
RouteValues = match!.RouteValues,
|
||||
Items = { ["ServiceProvider"] = _serviceProvider },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user