First Commit

This commit is contained in:
Jorge Luis caudillo esparza
2026-05-09 16:36:57 -07:00
parent 96ad4c0d3e
commit d0c284d9c0
131 changed files with 4009 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
namespace ADS.Helpers.Middleware.Http;
public sealed class ApiResponse<T>
{
public int StatusCode { get; init; }
public int TotalRows { get; init; }
public string StatusCodeText { get; init; } = string.Empty;
public string? ConsoleMessage { get; init; }
public UiMessage? ScreenMessage { get; init; }
public T? Value { get; init; }
}
public sealed class UiMessage
{
public int MessageType { get; init; }
public string Message { get; init; } = "";
public int MessageCode { get; init; }
}

View File

@@ -0,0 +1,62 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace ADS.Helpers.Middleware.Http;
public sealed class ApiResponseWrapFilter : IAsyncResultFilter
{
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
// Si es FileResult / Stream / etc., no lo toques
if (context.Result is FileResult)
{
await next();
return;
}
if (context.Result is ObjectResult obj)
{
// Si ya viene envuelto, no reenvolver
if (obj.Value is not null)
{
var t = obj.Value.GetType();
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ApiResponse<>))
{
await next();
return;
}
}
var code = obj.StatusCode ?? 200;
context.Result = new ObjectResult(new ApiResponse<object>
{
StatusCode = code,
StatusCodeText = ReasonPhrase(code),
Value = obj.Value
})
{ StatusCode = code };
await next();
return;
}
// Si no es ObjectResult (por ejemplo EmptyResult), déjalo pasar
await next();
}
private static string ReasonPhrase(int code) => code switch
{
200 => "OK",
201 => "Created",
202 => "Accepted",
204 => "NoContent",
400 => "BadRequest",
401 => "Unauthorized",
403 => "Forbidden",
404 => "NotFound",
409 => "Conflict",
422 => "UnprocessableEntity",
500 => "ServerError",
_ => "Status"
};
}

View File

@@ -0,0 +1,9 @@
namespace ADS.Helpers.Middleware.Http;
public sealed class PagedQuery
{
public string? Search { get; init; }
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 50;
public bool Pagination { get; init; } = true;
}

View File

@@ -0,0 +1,11 @@
namespace ADS.Helpers.Middleware.Http;
public sealed class RequestOf<T>
{
public T? Value { get; init; }
public string? Search { get; init; }
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 50;
public bool Pagination { get; init; } = true;
}