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 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user