feat: add Logs
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.domain.Projects;
|
||||
|
||||
namespace mws.backend.dotnet.application.Projects;
|
||||
|
||||
public record AddProjectMemberCommand(Guid UserId, Guid ProjectId, AddMemberRequest Request) : IRequest<ProjectMemberDto>;
|
||||
public record AddProjectMemberCommand(Guid UserId, Guid ProjectId, AddMemberRequest Request) : IRequest<ProjectMemberDto>, IAuditableRequest
|
||||
{
|
||||
public string Action => "ProjectMember.Add";
|
||||
public string EntityType => "ProjectMember";
|
||||
public Guid? EntityId => Request.UserId;
|
||||
}
|
||||
|
||||
public class AddProjectMemberHandler(IUnitOfWork uow) : IRequestHandler<AddProjectMemberCommand, ProjectMemberDto>
|
||||
public class AddProjectMemberHandler(IUnitOfWork uow, IAuditContext auditContext) : IRequestHandler<AddProjectMemberCommand, ProjectMemberDto>
|
||||
{
|
||||
public async Task<ProjectMemberDto> Handle(AddProjectMemberCommand command, CancellationToken ct)
|
||||
{
|
||||
@@ -46,6 +52,8 @@ public class AddProjectMemberHandler(IUnitOfWork uow) : IRequestHandler<AddProje
|
||||
});
|
||||
await uow.SaveChangesAsync(ct);
|
||||
|
||||
auditContext.EntityName = user.Username;
|
||||
|
||||
return new ProjectMemberDto
|
||||
{
|
||||
UserId = user.Id,
|
||||
|
||||
@@ -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.Projects;
|
||||
|
||||
namespace mws.backend.dotnet.application.Projects;
|
||||
|
||||
public record ArchiveProjectCommand(Guid UserId, Guid ProjectId) : IRequest;
|
||||
public record ArchiveProjectCommand(Guid UserId, Guid ProjectId) : IRequest, IAuditableRequest
|
||||
{
|
||||
public string Action => "Project.Archive";
|
||||
public string EntityType => "Project";
|
||||
public Guid? EntityId => ProjectId;
|
||||
}
|
||||
|
||||
public class ArchiveProjectHandler(IUnitOfWork uow, IPermissionService permissions) : IRequestHandler<ArchiveProjectCommand>
|
||||
public class ArchiveProjectHandler(IUnitOfWork uow, IPermissionService permissions, IAuditContext auditContext) : IRequestHandler<ArchiveProjectCommand>
|
||||
{
|
||||
public async Task Handle(ArchiveProjectCommand command, CancellationToken ct)
|
||||
{
|
||||
@@ -18,5 +24,7 @@ public class ArchiveProjectHandler(IUnitOfWork uow, IPermissionService permissio
|
||||
project.Status = ProjectStatus.Archived;
|
||||
project.UpdatedAt = DateTime.UtcNow;
|
||||
await uow.SaveChangesAsync(ct);
|
||||
|
||||
auditContext.EntityName = project.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
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.Projects;
|
||||
|
||||
namespace mws.backend.dotnet.application.Projects;
|
||||
|
||||
public record CreateProjectCommand(Guid UserId, CreateProjectRequest Request) : IRequest<ProjectDto>;
|
||||
public record CreateProjectCommand(Guid UserId, CreateProjectRequest Request) : IRequest<ProjectDto>, IAuditableRequest
|
||||
{
|
||||
public string Action => "Project.Create";
|
||||
public string EntityType => "Project";
|
||||
public string? EntityName => Request.Name;
|
||||
}
|
||||
|
||||
public class CreateProjectHandler(IUnitOfWork uow, IMapper mapper, IPermissionService permissions) : IRequestHandler<CreateProjectCommand, ProjectDto>
|
||||
{
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.domain.Projects;
|
||||
|
||||
namespace mws.backend.dotnet.application.Projects;
|
||||
|
||||
public record RemoveProjectMemberCommand(Guid UserId, Guid ProjectId, Guid MemberUserId) : IRequest;
|
||||
public record RemoveProjectMemberCommand(Guid UserId, Guid ProjectId, Guid MemberUserId) : IRequest, IAuditableRequest
|
||||
{
|
||||
public string Action => "ProjectMember.Remove";
|
||||
public string EntityType => "ProjectMember";
|
||||
public Guid? EntityId => MemberUserId;
|
||||
}
|
||||
|
||||
public class RemoveProjectMemberHandler(IUnitOfWork uow) : IRequestHandler<RemoveProjectMemberCommand>
|
||||
public class RemoveProjectMemberHandler(IUnitOfWork uow, IAuditContext auditContext) : IRequestHandler<RemoveProjectMemberCommand>
|
||||
{
|
||||
public async Task Handle(RemoveProjectMemberCommand command, CancellationToken ct)
|
||||
{
|
||||
@@ -15,7 +21,7 @@ public class RemoveProjectMemberHandler(IUnitOfWork uow) : IRequestHandler<Remov
|
||||
throw new ForbiddenException("Only the project owner can remove members");
|
||||
}
|
||||
|
||||
var member = await uow.Projects.GetMemberAsync(command.ProjectId, command.MemberUserId, ct)
|
||||
var member = await uow.Projects.GetMemberWithUserAsync(command.ProjectId, command.MemberUserId, ct)
|
||||
?? throw new NotFoundException("Member not found in project");
|
||||
|
||||
var owners = await uow.Projects.CountOwnersAsync(command.ProjectId, ct);
|
||||
@@ -27,5 +33,7 @@ public class RemoveProjectMemberHandler(IUnitOfWork uow) : IRequestHandler<Remov
|
||||
|
||||
uow.Projects.RemoveMember(member);
|
||||
await uow.SaveChangesAsync(ct);
|
||||
|
||||
auditContext.EntityName = member.User.Username;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.domain.Projects;
|
||||
|
||||
namespace mws.backend.dotnet.application.Projects;
|
||||
|
||||
public record UpdateMemberDocumentPermissionsCommand(
|
||||
Guid UserId, Guid ProjectId, Guid MemberUserId, UpdateMemberDocumentPermissionsRequest Request) : IRequest<ProjectMemberDto>;
|
||||
Guid UserId, Guid ProjectId, Guid MemberUserId, UpdateMemberDocumentPermissionsRequest Request) : IRequest<ProjectMemberDto>, IAuditableRequest
|
||||
{
|
||||
public string Action => "ProjectMember.UpdatePermissions";
|
||||
public string EntityType => "ProjectMember";
|
||||
public Guid? EntityId => MemberUserId;
|
||||
}
|
||||
|
||||
public class UpdateMemberDocumentPermissionsHandler(IUnitOfWork uow)
|
||||
public class UpdateMemberDocumentPermissionsHandler(IUnitOfWork uow, IAuditContext auditContext)
|
||||
: IRequestHandler<UpdateMemberDocumentPermissionsCommand, ProjectMemberDto>
|
||||
{
|
||||
public async Task<ProjectMemberDto> Handle(UpdateMemberDocumentPermissionsCommand command, CancellationToken ct)
|
||||
@@ -39,6 +45,8 @@ public class UpdateMemberDocumentPermissionsHandler(IUnitOfWork uow)
|
||||
permission.CanDelete = request.CanDeleteDocuments;
|
||||
await uow.SaveChangesAsync(ct);
|
||||
|
||||
auditContext.EntityName = member.User.Username;
|
||||
|
||||
return new ProjectMemberDto
|
||||
{
|
||||
UserId = member.UserId,
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
using AutoMapper;
|
||||
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.Projects;
|
||||
|
||||
public record UpdateProjectCommand(Guid UserId, Guid ProjectId, UpdateProjectRequest Request) : IRequest<ProjectDto>;
|
||||
public record UpdateProjectCommand(Guid UserId, Guid ProjectId, UpdateProjectRequest Request) : IRequest<ProjectDto>, IAuditableRequest
|
||||
{
|
||||
public string Action => "Project.Update";
|
||||
public string EntityType => "Project";
|
||||
public Guid? EntityId => ProjectId;
|
||||
public string? EntityName => Request.Name;
|
||||
}
|
||||
|
||||
public class UpdateProjectHandler(IUnitOfWork uow, IMapper mapper, IPermissionService permissions) : IRequestHandler<UpdateProjectCommand, ProjectDto>
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using mws.backend.dotnet.application.Audit;
|
||||
using mws.backend.dotnet.domain.Projects;
|
||||
|
||||
namespace mws.backend.dotnet.application.Projects;
|
||||
@@ -41,9 +42,10 @@ public class UpdateMemberDocumentPermissionsRequest
|
||||
public bool CanDeleteDocuments { get; set; }
|
||||
}
|
||||
|
||||
public class ProjectDto
|
||||
public class ProjectDto : IHasEntityId
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid EntityId => Id;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public ProjectStatus Status { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user