- 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.
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using PnvPanel.Application.Auth;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using LiteCqrs;
|
|
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);
|
|
}
|
|
}
|