feat: add Logs
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
using System.Text;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.application.Permissions;
|
||||
using mws.backend.dotnet.domain.Documents;
|
||||
|
||||
namespace mws.backend.dotnet.application.Documents;
|
||||
|
||||
public record CreateDocumentCommand(Guid UserId, Guid ProjectId, CreateDocumentRequest Request) : IRequest<DocumentDto>;
|
||||
public record CreateDocumentCommand(Guid UserId, Guid ProjectId, CreateDocumentRequest Request) : IRequest<DocumentDto>, IAuditableRequest
|
||||
{
|
||||
public string Action => "Document.Create";
|
||||
public string EntityType => "Document";
|
||||
public string? EntityName => Request.Title;
|
||||
}
|
||||
|
||||
public class CreateDocumentHandler(IUnitOfWork uow, IMapper mapper, IDocumentContentStore contentStore)
|
||||
: IRequestHandler<CreateDocumentCommand, DocumentDto>
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.application.Permissions;
|
||||
|
||||
namespace mws.backend.dotnet.application.Documents;
|
||||
|
||||
public record DeleteDocumentCommand(Guid UserId, Guid DocumentId) : IRequest;
|
||||
public record DeleteDocumentCommand(Guid UserId, Guid DocumentId) : IRequest, IAuditableRequest
|
||||
{
|
||||
public string Action => "Document.Delete";
|
||||
public string EntityType => "Document";
|
||||
public Guid? EntityId => DocumentId;
|
||||
}
|
||||
|
||||
public class DeleteDocumentHandler(IUnitOfWork uow, IDocumentContentStore contentStore)
|
||||
public class DeleteDocumentHandler(IUnitOfWork uow, IDocumentContentStore contentStore, IAuditContext auditContext)
|
||||
: IRequestHandler<DeleteDocumentCommand>
|
||||
{
|
||||
public async Task Handle(DeleteDocumentCommand command, CancellationToken ct)
|
||||
@@ -25,6 +31,8 @@ public class DeleteDocumentHandler(IUnitOfWork uow, IDocumentContentStore conten
|
||||
uow.Documents.Remove(doc);
|
||||
await uow.SaveChangesAsync(ct);
|
||||
|
||||
auditContext.EntityName = doc.Title;
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
await contentStore.DeleteAsync(key, ct);
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.application.Permissions;
|
||||
using mws.backend.dotnet.domain.Documents;
|
||||
|
||||
namespace mws.backend.dotnet.application.Documents;
|
||||
|
||||
public record MoveDocumentCommand(Guid UserId, Guid DocumentId, Guid? NewParentId) : IRequest;
|
||||
public record MoveDocumentCommand(Guid UserId, Guid DocumentId, Guid? NewParentId) : IRequest, IAuditableRequest
|
||||
{
|
||||
public string Action => "Document.Move";
|
||||
public string EntityType => "Document";
|
||||
public Guid? EntityId => DocumentId;
|
||||
}
|
||||
|
||||
public class MoveDocumentHandler(IUnitOfWork uow) : IRequestHandler<MoveDocumentCommand>
|
||||
public class MoveDocumentHandler(IUnitOfWork uow, IAuditContext auditContext) : IRequestHandler<MoveDocumentCommand>
|
||||
{
|
||||
public async Task Handle(MoveDocumentCommand command, CancellationToken ct)
|
||||
{
|
||||
@@ -47,5 +53,7 @@ public class MoveDocumentHandler(IUnitOfWork uow) : IRequestHandler<MoveDocument
|
||||
doc.UpdatedAt = DateTime.UtcNow;
|
||||
doc.UpdatedBy = command.UserId;
|
||||
await uow.SaveChangesAsync(ct);
|
||||
|
||||
auditContext.EntityName = doc.Title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
using System.Text;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.application.Permissions;
|
||||
using mws.backend.dotnet.domain.Documents;
|
||||
|
||||
namespace mws.backend.dotnet.application.Documents;
|
||||
|
||||
public record UpdateDocumentCommand(Guid UserId, Guid DocumentId, UpdateDocumentRequest Request) : IRequest<DocumentDto>;
|
||||
public record UpdateDocumentCommand(Guid UserId, Guid DocumentId, UpdateDocumentRequest Request) : IRequest<DocumentDto>, IAuditableRequest
|
||||
{
|
||||
public string Action => "Document.Update";
|
||||
public string EntityType => "Document";
|
||||
public Guid? EntityId => DocumentId;
|
||||
public string? EntityName => Request.Title;
|
||||
}
|
||||
|
||||
public class UpdateDocumentHandler(IUnitOfWork uow, IMapper mapper, IDocumentContentStore contentStore)
|
||||
: IRequestHandler<UpdateDocumentCommand, DocumentDto>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.domain.Documents;
|
||||
|
||||
namespace mws.backend.dotnet.application.Documents;
|
||||
@@ -21,9 +22,10 @@ public class MoveDocumentRequest
|
||||
public Guid? NewParentId { get; set; }
|
||||
}
|
||||
|
||||
public class DocumentDto
|
||||
public class DocumentDto : IHasEntityId
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid EntityId => Id;
|
||||
public Guid ProjectId { get; set; }
|
||||
public Guid? ParentId { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user