Enhance admin maintenance functionality with new endpoints and response types
- Added new DELETE endpoints for managing audit logs and disabled apps in the admin maintenance section. - Updated existing endpoint for closed tickets to use a unified response type, `MaintenanceCleanupResponseDto`. - Enhanced API documentation to reflect the new operations and their expected request/response formats. - Improved frontend integration with new functions for deleting old audit logs and disabled apps, including user confirmation prompts. - Added localization support for new maintenance actions in both Russian and English.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using PnvPanel.Api.Common;
|
||||
using PnvPanel.Application.Admin.Maintenance;
|
||||
using PnvPanel.Application.Common.Messaging;
|
||||
using PnvPanel.Application.Common.Models;
|
||||
using PnvPanel.Infrastructure.Identity;
|
||||
|
||||
namespace PnvPanel.Api.Endpoints;
|
||||
@@ -15,7 +16,13 @@ public static class AdminMaintenanceEndpoints
|
||||
|
||||
admin
|
||||
.MapDelete("/tickets/closed", DeleteClosedTickets)
|
||||
.Produces<DeleteClosedTicketsResponseDto>();
|
||||
.Produces<MaintenanceCleanupResponseDto>();
|
||||
admin
|
||||
.MapDelete("/audit-logs", DeleteOldAuditLogs)
|
||||
.Produces<MaintenanceCleanupResponseDto>();
|
||||
admin
|
||||
.MapDelete("/apps/disabled", DeleteDisabledApps)
|
||||
.Produces<MaintenanceCleanupResponseDto>();
|
||||
|
||||
return app;
|
||||
}
|
||||
@@ -26,11 +33,35 @@ public static class AdminMaintenanceEndpoints
|
||||
)
|
||||
{
|
||||
var result = await sender.Send(new DeleteClosedTicketsCommand(), cancellationToken);
|
||||
if (!result.IsSuccess)
|
||||
return result.ToHttpResult();
|
||||
|
||||
return Results.Ok(new DeleteClosedTicketsResponseDto(result.Value));
|
||||
return ToResponse(result);
|
||||
}
|
||||
|
||||
private static async Task<IResult> DeleteOldAuditLogs(
|
||||
int olderThanDays,
|
||||
ISender sender,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var result = await sender.Send(
|
||||
new DeleteOldAuditLogsCommand(olderThanDays),
|
||||
cancellationToken
|
||||
);
|
||||
return ToResponse(result);
|
||||
}
|
||||
|
||||
private static async Task<IResult> DeleteDisabledApps(
|
||||
ISender sender,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var result = await sender.Send(new DeleteDisabledAppsCommand(), cancellationToken);
|
||||
return ToResponse(result);
|
||||
}
|
||||
|
||||
private static IResult ToResponse(Result<int> result) =>
|
||||
result.IsSuccess
|
||||
? Results.Ok(new MaintenanceCleanupResponseDto(result.Value))
|
||||
: result.ToHttpResult();
|
||||
}
|
||||
|
||||
public sealed record DeleteClosedTicketsResponseDto(int DeletedCount);
|
||||
public sealed record MaintenanceCleanupResponseDto(int DeletedCount);
|
||||
|
||||
Reference in New Issue
Block a user