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

@@ -13402,6 +13402,26 @@
"sourceCardinality": "NoneRelationship",
"targetCardinality": "NoneRelationship",
"oldName": ""
},
{
"objectType": "ForeignKey_MSSQL",
"name": "fk_UserService_AcceptContractRequestResponse_1",
"fields": [
"AcceptContract"
],
"referencedSchema": "FrontOffice",
"referencedTable": "AcceptContractRequestResponse",
"referencedFields": [
"Token"
],
"onDelete": "",
"onUpdate": "",
"isNotForReplication": false,
"isEnabled": true,
"comment": "",
"sourceCardinality": "NoneRelationship",
"targetCardinality": "NoneRelationship",
"oldName": ""
}
],
"uniques": [],
@@ -13685,7 +13705,7 @@
"indexes": [],
"primaryKey": {
"objectType": "PrimaryKey_MSSQL",
"name": "",
"name": "_copy_15",
"fields": [],
"fillFactor": 0,
"oldName": "",
@@ -13726,6 +13746,99 @@
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
{
"objectType": "Table_MSSQL",
"name": "AcceptContractRequestResponse",
"comment": "خروجی واکشی توکن",
"owner": "",
"isChangeTracking": false,
"isTrackColumnsUpdated": false,
"oldName": "",
"isSystemTable": false,
"createTime": "",
"modifyTime": "",
"objectID": 6042,
"numberOfRows": 0,
"identityCurrent": 0,
"dataLength": 0,
"indexLength": 0,
"fields": [
{
"objectType": "TableField_MSSQL",
"name": "Token",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "توکن",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Token",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": true,
"isExistingField": false,
"identitySeed": -2147483648,
"identityIncrement": -2147483648,
"identityIsNotForReplication": false
}
],
"indexes": [],
"primaryKey": {
"objectType": "PrimaryKey_MSSQL",
"name": "_copy_46_copy_1_copy_1",
"fields": [],
"fillFactor": 0,
"oldName": "",
"isClustered": false,
"isPadded": false,
"noRecomputeStatistics": false,
"ignoreDuplicatedKeyValues": false,
"allowRowLocks": false,
"allowPageLocks": false,
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
"foreignKeys": [],
"uniques": [],
"checks": [],
"triggers": [],
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
}
],
"views": []
@@ -14707,6 +14820,22 @@
"b": 147,
"a": 1
}
},
{
"type": "table",
"schemaName": "FrontOffice",
"tableName": "AcceptContractRequestResponse",
"x": 604,
"y": 3227,
"width": 400,
"height": 106,
"isBold": false,
"titleColor": {
"r": 200,
"g": 255,
"b": 160,
"a": 1
}
}
],
"layers": [],
@@ -16944,6 +17073,44 @@
"isFontItalic": false,
"isVisible": false
}
},
{
"name": "fk_UserService_AcceptContractRequestResponse_1",
"sourceTableName": "UserService",
"sourceSchemaName": "FrontOffice",
"lineWidth": 1,
"visible": true,
"vertices": [
{
"x": 965,
"y": 3590
},
{
"x": 804,
"y": 3590
},
{
"x": 804,
"y": 3348
}
],
"label": {
"x": 628,
"y": 3550,
"width": 347,
"height": 32,
"fontName": "Sans",
"fontSize": 14,
"fontColor": {
"r": 51,
"g": 51,
"b": 51,
"a": 1
},
"isFontBold": false,
"isFontItalic": false,
"isVisible": false
}
}
],
"viewRelations": []

View File

@@ -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; }

View File

@@ -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; }
}

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))
{
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>();
}
}

View File

@@ -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">

View File

@@ -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");
}

View File

@@ -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;

View File

@@ -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);
};
}