This commit is contained in:
masoodafar-web
2025-11-16 03:28:34 +03:30
parent e2107d1ac8
commit eed625c722
12 changed files with 216 additions and 70 deletions

View File

@@ -1,16 +1,26 @@
using CMSMicroservice.Protobuf.Protos.UserContract;
namespace FrontOffice.BFF.Application.UserCQ.Commands.AcceptContract;
public class AcceptContractCommandHandler : IRequestHandler<AcceptContractCommand, Unit>
{
private readonly IApplicationContractContext _context;
private readonly ICurrentUserService _currentUserService;
public AcceptContractCommandHandler(IApplicationContractContext context)
public AcceptContractCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
{
_context = context;
_currentUserService = currentUserService;
}
public async Task<Unit> Handle(AcceptContractCommand request, CancellationToken cancellationToken)
{
//TODO: Implement your business logic
await _context.UserContract.CreateNewUserContractAsync(new CreateNewUserContractRequest()
{
SignGuid = request.SignGuid,
UserId = long.Parse(_currentUserService.UserId ?? throw new InvalidOperationException()),
ContractId = 1,
SignedPdfFile = request.ContractHtml,
}, cancellationToken: cancellationToken);
return new Unit();
}
}

View File

@@ -1,7 +0,0 @@
namespace FrontOffice.BFF.Application.UserCQ.Commands.CreateContractOtpToken;
public record CreateContractOtpTokenCommand : IRequest<Unit>
{
//شناسه یکتای قرارداد
public string? CotractGuid { get; init; }
}

View File

@@ -1,22 +0,0 @@
using CMSMicroservice.Protobuf.Protos.OtpToken;
namespace FrontOffice.BFF.Application.UserCQ.Commands.CreateContractOtpToken;
public class CreateContractOtpTokenCommandHandler : IRequestHandler<CreateContractOtpTokenCommand, Unit>
{
private readonly IApplicationContractContext _context;
public CreateContractOtpTokenCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(CreateContractOtpTokenCommand request, CancellationToken cancellationToken)
{
var response = await _context.OtpToken.CreateNewOtpTokenAsync(request: new CreateNewOtpTokenRequest()
{
}, cancellationToken: cancellationToken);
if (response.Success && !string.IsNullOrWhiteSpace(response.Code))
await _kavenegarService.VerifyLookup(mobile: request.Mobile, response.Code);
}
}

View File

@@ -1,14 +0,0 @@
namespace FrontOffice.BFF.Application.UserCQ.Commands.CreateContractOtpToken;
public class CreateContractOtpTokenCommandValidator : AbstractValidator<CreateContractOtpTokenCommand>
{
public CreateContractOtpTokenCommandValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateContractOtpTokenCommand>.CreateWithOptions((CreateContractOtpTokenCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -1,22 +1,44 @@
using System.Text;
using CMSMicroservice.Protobuf.Protos.OtpToken;
namespace FrontOffice.BFF.Application.UserCQ.Commands.CreateNewOtpToken;
public class CreateNewOtpTokenCommandHandler : IRequestHandler<CreateNewOtpTokenCommand, CreateNewOtpTokenResponseDto>
{
private readonly IApplicationContractContext _context;
private readonly IKavenegarService _kavenegarService;
private readonly ICurrentUserService _currentUserService;
public CreateNewOtpTokenCommandHandler(IApplicationContractContext context, IKavenegarService kavenegarService)
public CreateNewOtpTokenCommandHandler(IApplicationContractContext context, IKavenegarService kavenegarService, ICurrentUserService currentUserService)
{
_context = context;
_kavenegarService = kavenegarService;
_currentUserService = currentUserService;
}
public async Task<CreateNewOtpTokenResponseDto> Handle(CreateNewOtpTokenCommand request, CancellationToken cancellationToken)
public async Task<CreateNewOtpTokenResponseDto> Handle(CreateNewOtpTokenCommand request,
CancellationToken cancellationToken)
{
var response = await _context.OtpToken.CreateNewOtpTokenAsync(request: request.Adapt<CreateNewOtpTokenRequest>(), cancellationToken: cancellationToken);
var response =
await _context.OtpToken.CreateNewOtpTokenAsync(request: request.Adapt<CreateNewOtpTokenRequest>(),
cancellationToken: cancellationToken);
if (response.Success && !string.IsNullOrWhiteSpace(response.Code))
await _kavenegarService.VerifyLookup(mobile: request.Mobile, response.Code);
{
if (!string.IsNullOrWhiteSpace(request.SignGuid))
await _kavenegarService.Send(mobile: request.Mobile, new StringBuilder("سلام ")
.Append(_currentUserService.FirstName+" "+_currentUserService.LastName)
.Append(" عزیز")
.AppendLine("کد یک بار مصرف شما: ")
.Append(response.Code)
.AppendLine("شناسه امضاء: ")
.AppendLine(request.SignGuid)
.AppendLine("کارابازار")
.ToString());
else
await _kavenegarService.VerifyLookup(mobile: request.Mobile, response.Code);
}
return response.Adapt<CreateNewOtpTokenResponseDto>();
}
}
}