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:
+45
@@ -0,0 +1,45 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PnvPanel.Application.Auth;
|
||||
using PnvPanel.Application.Common.Interfaces;
|
||||
using PnvPanel.Application.Common.Messaging;
|
||||
using PnvPanel.Application.Common.Models;
|
||||
using PnvPanel.Domain.Audit;
|
||||
|
||||
namespace PnvPanel.Application.Admin.Maintenance;
|
||||
|
||||
public sealed class DeleteDisabledAppsCommandHandler(
|
||||
IAppDbContext dbContext,
|
||||
ICurrentUser currentUser
|
||||
) : ICommandHandler<DeleteDisabledAppsCommand, Result<int>>
|
||||
{
|
||||
public async Task<Result<int>> Handle(
|
||||
DeleteDisabledAppsCommand command,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
if (currentUser.UserId is not { } adminId)
|
||||
return Result.Failure<int>(AuthErrors.Unauthorized);
|
||||
|
||||
var apps = await dbContext
|
||||
.ClientApps.Where(a => !a.IsEnabled)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
if (apps.Count == 0)
|
||||
return Result.Success(0);
|
||||
|
||||
dbContext.ClientApps.RemoveRange(apps);
|
||||
|
||||
dbContext.AuditLogs.Add(
|
||||
AuditLog.Create(
|
||||
adminId,
|
||||
"DisabledAppsCleanedUp",
|
||||
"ClientApp",
|
||||
"bulk",
|
||||
metadata: $"{{\"count\":{apps.Count}}}",
|
||||
AuditSource.Web
|
||||
)
|
||||
);
|
||||
|
||||
return Result.Success(apps.Count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user