Refactor AcceptContractCommandHandler to return AcceptContractResponseDto and integrate OTP verification
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
|
using CMSMicroservice.Protobuf.Protos.OtpToken;
|
||||||
using CMSMicroservice.Protobuf.Protos.UserContract;
|
using CMSMicroservice.Protobuf.Protos.UserContract;
|
||||||
|
using FrontOffice.BFF.Application.UserCQ.Commands.VerifyOtpToken;
|
||||||
|
|
||||||
namespace FrontOffice.BFF.Application.UserCQ.Commands.AcceptContract;
|
namespace FrontOffice.BFF.Application.UserCQ.Commands.AcceptContract;
|
||||||
public class AcceptContractCommandHandler : IRequestHandler<AcceptContractCommand, Unit>
|
public class AcceptContractCommandHandler : IRequestHandler<AcceptContractCommand, AcceptContractResponseDto>
|
||||||
{
|
{
|
||||||
private readonly IApplicationContractContext _context;
|
private readonly IApplicationContractContext _context;
|
||||||
private readonly ICurrentUserService _currentUserService;
|
private readonly ICurrentUserService _currentUserService;
|
||||||
@@ -12,7 +14,7 @@ public class AcceptContractCommandHandler : IRequestHandler<AcceptContractComman
|
|||||||
_currentUserService = currentUserService;
|
_currentUserService = currentUserService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Unit> Handle(AcceptContractCommand request, CancellationToken cancellationToken)
|
public async Task<AcceptContractResponseDto> Handle(AcceptContractCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await _context.UserContract.CreateNewUserContractAsync(new CreateNewUserContractRequest()
|
await _context.UserContract.CreateNewUserContractAsync(new CreateNewUserContractRequest()
|
||||||
{
|
{
|
||||||
@@ -21,6 +23,17 @@ public class AcceptContractCommandHandler : IRequestHandler<AcceptContractComman
|
|||||||
ContractId = 1,
|
ContractId = 1,
|
||||||
SignedPdfFile = request.ContractHtml,
|
SignedPdfFile = request.ContractHtml,
|
||||||
}, cancellationToken: cancellationToken);
|
}, cancellationToken: cancellationToken);
|
||||||
return new Unit();
|
var response = await _context.OtpToken.VerifyOtpTokenAsync(request: request.Adapt<VerifyOtpTokenRequest>(), 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using CMSMicroservice.Protobuf.Protos.OtpToken;
|
|||||||
using CMSMicroservice.Protobuf.Protos.Package;
|
using CMSMicroservice.Protobuf.Protos.Package;
|
||||||
using CMSMicroservice.Protobuf.Protos.User;
|
using CMSMicroservice.Protobuf.Protos.User;
|
||||||
using CMSMicroservice.Protobuf.Protos.UserAddress;
|
using CMSMicroservice.Protobuf.Protos.UserAddress;
|
||||||
|
using CMSMicroservice.Protobuf.Protos.UserContract;
|
||||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -43,7 +44,7 @@ public class ApplicationContractContext : IApplicationContractContext
|
|||||||
public PackageContract.PackageContractClient Package => GetService<PackageContract.PackageContractClient>();
|
public PackageContract.PackageContractClient Package => GetService<PackageContract.PackageContractClient>();
|
||||||
|
|
||||||
public UserContract.UserContractClient User => GetService<UserContract.UserContractClient>();
|
public UserContract.UserContractClient User => GetService<UserContract.UserContractClient>();
|
||||||
|
public UserContractContract.UserContractContractClient UserContract => GetService<UserContractContract.UserContractContractClient>();
|
||||||
public UserAddressContract.UserAddressContractClient UserAddress => GetService<UserAddressContract.UserAddressContractClient>();
|
public UserAddressContract.UserAddressContractClient UserAddress => GetService<UserAddressContract.UserAddressContractClient>();
|
||||||
|
|
||||||
public UserOrderContract.UserOrderContractClient UserOrder => GetService<UserOrderContract.UserOrderContractClient>();
|
public UserOrderContract.UserOrderContractClient UserOrder => GetService<UserOrderContract.UserOrderContractClient>();
|
||||||
|
|||||||
Reference in New Issue
Block a user