feat: Enhance network membership and withdrawal processing with user tracking and logging

This commit is contained in:
masoodafar-web
2025-12-01 20:52:18 +03:30
parent 4aaf2247ff
commit 25fc73ae28
47 changed files with 9545 additions and 284 deletions

View File

@@ -3,7 +3,7 @@ namespace CMSMicroservice.Application.NetworkMembershipCQ.Commands.JoinNetwork;
/// <summary>
/// Command برای افزودن کاربر به شبکه دوتایی (Binary Network)
/// </summary>
public record JoinNetworkCommand : IRequest<Unit>
public record JoinNetworkCommand : IRequest<long>
{
/// <summary>
/// شناسه کاربر که می‌خواهد به شبکه بپیوندد

View File

@@ -1,15 +1,19 @@
namespace CMSMicroservice.Application.NetworkMembershipCQ.Commands.JoinNetwork;
public class JoinNetworkCommandHandler : IRequestHandler<JoinNetworkCommand, Unit>
public class JoinNetworkCommandHandler : IRequestHandler<JoinNetworkCommand, long>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public JoinNetworkCommandHandler(IApplicationDbContext context)
public JoinNetworkCommandHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<Unit> Handle(JoinNetworkCommand request, CancellationToken cancellationToken)
public async Task<long> Handle(JoinNetworkCommand request, CancellationToken cancellationToken)
{
// بررسی وجود کاربر
var user = await _context.Users
@@ -69,12 +73,12 @@ public class JoinNetworkCommandHandler : IRequestHandler<JoinNetworkCommand, Uni
NewLegPosition = request.LegPosition,
Action = NetworkMembershipAction.Join,
Reason = request.Reason ?? "عضویت در شبکه",
PerformedBy = "System" // TODO: باید از Current User گرفته شود
PerformedBy = _currentUser.GetPerformedBy()
};
await _context.NetworkMembershipHistories.AddAsync(history, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
return user.Id;
}
}

View File

@@ -3,10 +3,14 @@ namespace CMSMicroservice.Application.NetworkMembershipCQ.Commands.MoveInNetwork
public class MoveInNetworkCommandHandler : IRequestHandler<MoveInNetworkCommand, Unit>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public MoveInNetworkCommandHandler(IApplicationDbContext context)
public MoveInNetworkCommandHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<Unit> Handle(MoveInNetworkCommand request, CancellationToken cancellationToken)

View File

@@ -3,10 +3,14 @@ namespace CMSMicroservice.Application.NetworkMembershipCQ.Commands.RemoveFromNet
public class RemoveFromNetworkCommandHandler : IRequestHandler<RemoveFromNetworkCommand, Unit>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public RemoveFromNetworkCommandHandler(IApplicationDbContext context)
public RemoveFromNetworkCommandHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<Unit> Handle(RemoveFromNetworkCommand request, CancellationToken cancellationToken)