47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using CMSMicroservice.Protobuf.Protos.OtpToken;
|
|
using CMSMicroservice.Protobuf.Protos.UserContract;
|
|
using FrontOffice.BFF.Application.UserCQ.Commands.VerifyOtpToken;
|
|
|
|
namespace FrontOffice.BFF.Application.UserCQ.Commands.AcceptContract;
|
|
public class AcceptContractCommandHandler : IRequestHandler<AcceptContractCommand, AcceptContractResponseDto>
|
|
{
|
|
private readonly IApplicationContractContext _context;
|
|
private readonly ICurrentUserService _currentUserService;
|
|
|
|
public AcceptContractCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
|
{
|
|
_context = context;
|
|
_currentUserService = currentUserService;
|
|
}
|
|
|
|
public async Task<AcceptContractResponseDto> Handle(AcceptContractCommand request, CancellationToken cancellationToken)
|
|
{
|
|
await _context.UserContract.CreateNewUserContractAsync(new CreateNewUserContractRequest()
|
|
{
|
|
SignGuid = request.SignGuid,
|
|
UserId = long.Parse(_currentUserService.UserId ?? throw new InvalidOperationException()),
|
|
ContractId = 1,
|
|
SignedPdfFile = request.ContractHtml,
|
|
}, cancellationToken: cancellationToken);
|
|
var verifyRequest = new VerifyOtpTokenRequest()
|
|
{
|
|
Mobile = _currentUserService.MobileNumber,
|
|
Code = request.Code,
|
|
Purpose = "signContract",
|
|
|
|
};
|
|
var response = await _context.OtpToken.VerifyOtpTokenAsync(request:verifyRequest, cancellationToken: cancellationToken);
|
|
var result = response.Adapt<AcceptContractResponseDto>();
|
|
if (response.Success && response.UserId.HasValue && response.UserId.Value > 0)
|
|
{
|
|
var token = await _context.User.GetJwtTokenAsync(request: new()
|
|
{
|
|
Id = response.UserId.Value
|
|
}, cancellationToken: cancellationToken);
|
|
|
|
result.Token = token?.Token;
|
|
}
|
|
return result;
|
|
}
|
|
}
|