udpate
This commit is contained in:
@@ -2,6 +2,7 @@ using CMSMicroservice.Protobuf.Protos.OtpToken;
|
||||
using CMSMicroservice.Protobuf.Protos.Package;
|
||||
using CMSMicroservice.Protobuf.Protos.User;
|
||||
using CMSMicroservice.Protobuf.Protos.UserAddress;
|
||||
using CMSMicroservice.Protobuf.Protos.UserContract;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using PYMSMicroservice.Protobuf.Protos.Transaction;
|
||||
|
||||
@@ -18,6 +19,7 @@ public interface IApplicationContractContext
|
||||
#region CMS
|
||||
PackageContract.PackageContractClient Package { get; }
|
||||
UserContract.UserContractClient User { get; }
|
||||
UserContractContract.UserContractContractClient UserContract { get; }
|
||||
UserAddressContract.UserAddressContractClient UserAddress { get; }
|
||||
UserOrderContract.UserOrderContractClient UserOrder { get; }
|
||||
OtpTokenContract.OtpTokenContractClient OtpToken { get; }
|
||||
|
||||
@@ -3,4 +3,7 @@ namespace FrontOffice.BFF.Application.Common.Interfaces;
|
||||
public interface ICurrentUserService
|
||||
{
|
||||
string? UserId { get; }
|
||||
string? FirstName { get; }
|
||||
string? LastName { get; }
|
||||
string? MobileNumber { get; }
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace FrontOffice.BFF.Application.UserCQ.Commands.CreateContractOtpToken;
|
||||
public record CreateContractOtpTokenCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه یکتای قرارداد
|
||||
public string? CotractGuid { get; init; }
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Afrino.PYMSMicroservice.Protobuf" Version="0.0.11" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.118" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.119" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.33.0" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.54.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.76.0">
|
||||
|
||||
@@ -14,4 +14,7 @@ public class CurrentUserService : ICurrentUserService
|
||||
}
|
||||
|
||||
public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
public string? FirstName => _httpContextAccessor.HttpContext?.User?.FindFirstValue("FirstName");
|
||||
public string? LastName => _httpContextAccessor.HttpContext?.User?.FindFirstValue("LastName");
|
||||
public string? MobileNumber => _httpContextAccessor.HttpContext?.User?.FindFirstValue("MobileNumber");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.AcceptContract;
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.CreateContractOtpToken;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.UpdateUser;
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.DeleteUser;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using FluentValidation;
|
||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||
namespace FrontOfficeMicroservice.Protobuf.Validator.User;
|
||||
|
||||
public class CreateContractOtpTokenRequestValidator : AbstractValidator<CreateContractOtpTokenRequest>
|
||||
{
|
||||
public CreateContractOtpTokenRequestValidator()
|
||||
{
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateContractOtpTokenRequest>.CreateWithOptions((CreateContractOtpTokenRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user