- Replaced instances of the previous messaging system with LiteCqrs across various application components, enhancing the CQRS implementation. - Updated dependency injection to register LiteCqrs services and behaviors, streamlining command and query handling. - Adjusted multiple command and query handlers to align with the new messaging framework, ensuring consistent functionality and improved maintainability. - Added LiteCqrs package reference in the project file for better dependency management.
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using PnvPanel.Api.Common;
|
|
using PnvPanel.Application.Admin.Audit;
|
|
using PnvPanel.Application.Admin.Stats;
|
|
using LiteCqrs;
|
|
using PnvPanel.Application.Common.Models;
|
|
using PnvPanel.Domain.Audit;
|
|
using PnvPanel.Infrastructure.Identity;
|
|
|
|
namespace PnvPanel.Api.Endpoints;
|
|
|
|
public static class AdminStatsEndpoints
|
|
{
|
|
public static IEndpointRouteBuilder MapAdminStatsEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
var admin = app.MapGroup("/api/admin")
|
|
.WithTags("Admin.Stats")
|
|
.RequireAuthorization(policy => policy.RequireRole(RoleNames.Admin));
|
|
|
|
admin.MapGet("/stats", GetStats).Produces<StatsDto>();
|
|
admin.MapGet("/audit", GetAudit).Produces<PagedList<AuditLogDto>>();
|
|
|
|
return app;
|
|
}
|
|
|
|
private static async Task<IResult> GetStats(ISender sender, CancellationToken cancellationToken)
|
|
{
|
|
var result = await sender.Send(new GetStatsQuery(), cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
|
|
private static async Task<IResult> GetAudit(
|
|
int page,
|
|
int pageSize,
|
|
AuditSource? source,
|
|
string? targetType,
|
|
string? action,
|
|
ISender sender,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var query = new ListAuditLogsQuery(
|
|
page <= 0 ? 1 : page,
|
|
pageSize <= 0 ? 50 : pageSize,
|
|
source,
|
|
targetType,
|
|
action
|
|
);
|
|
var result = await sender.Send(query, cancellationToken);
|
|
return result.ToHttpResult();
|
|
}
|
|
}
|