2026-08-14 08:46:06 +07:00
|
|
|
using MediatR;
|
2026-09-20 16:21:15 +07:00
|
|
|
using mws.backend.dotnet.application.Audit;
|
2026-08-19 23:25:08 +07:00
|
|
|
using mws.backend.dotnet.application.Common;
|
2026-09-12 19:40:59 +07:00
|
|
|
using mws.backend.dotnet.application.Permissions;
|
2026-08-19 23:25:08 +07:00
|
|
|
using mws.backend.dotnet.domain.Projects;
|
2026-08-14 08:46:06 +07:00
|
|
|
|
2026-08-19 23:25:08 +07:00
|
|
|
namespace mws.backend.dotnet.application.Projects;
|
2026-08-14 08:46:06 +07:00
|
|
|
|
2026-09-20 16:21:15 +07:00
|
|
|
public record ArchiveProjectCommand(Guid UserId, Guid ProjectId) : IRequest, IAuditableRequest
|
|
|
|
|
{
|
|
|
|
|
public string Action => "Project.Archive";
|
|
|
|
|
public string EntityType => "Project";
|
|
|
|
|
public Guid? EntityId => ProjectId;
|
|
|
|
|
}
|
2026-08-14 08:46:06 +07:00
|
|
|
|
2026-09-20 16:21:15 +07:00
|
|
|
public class ArchiveProjectHandler(IUnitOfWork uow, IPermissionService permissions, IAuditContext auditContext) : IRequestHandler<ArchiveProjectCommand>
|
2026-08-14 08:46:06 +07:00
|
|
|
{
|
|
|
|
|
public async Task Handle(ArchiveProjectCommand command, CancellationToken ct)
|
|
|
|
|
{
|
2026-09-12 19:40:59 +07:00
|
|
|
await permissions.EnsureAsync(command.UserId, "projects", PermissionAction.Delete, ct);
|
2026-08-14 08:46:06 +07:00
|
|
|
|
2026-09-12 19:40:59 +07:00
|
|
|
var project = await ProjectAccess.GetForUserOrThrowAsync(uow, command.UserId, command.ProjectId, ct);
|
2026-08-14 08:46:06 +07:00
|
|
|
|
|
|
|
|
project.Status = ProjectStatus.Archived;
|
|
|
|
|
project.UpdatedAt = DateTime.UtcNow;
|
|
|
|
|
await uow.SaveChangesAsync(ct);
|
2026-09-20 16:21:15 +07:00
|
|
|
|
|
|
|
|
auditContext.EntityName = project.Name;
|
2026-08-14 08:46:06 +07:00
|
|
|
}
|
|
|
|
|
}
|