This commit is contained in:
masoodafar-web
2025-12-02 03:32:50 +03:30
parent 27f59f0c30
commit bcf2bc2a52
23 changed files with 5712 additions and 31 deletions

View File

@@ -1,3 +0,0 @@
# FrontOffice.BFF
FrontOffice BFF

5470
docs/CMS.sql Normal file

File diff suppressed because one or more lines are too long

View File

@@ -8,6 +8,8 @@ using CMSMicroservice.Protobuf.Protos.ProductImages;
using CMSMicroservice.Protobuf.Protos.User;
using CMSMicroservice.Protobuf.Protos.UserAddress;
using CMSMicroservice.Protobuf.Protos.UserCarts;
using CMSMicroservice.Protobuf.Protos.Commission;
using CMSMicroservice.Protobuf.Protos.Configuration;
using CMSMicroservice.Protobuf.Protos.UserContract;
using CMSMicroservice.Protobuf.Protos.UserOrder;
using CMSMicroservice.Protobuf.Protos.UserWallet;
@@ -39,6 +41,8 @@ public interface IApplicationContractContext
OtpTokenContract.OtpTokenContractClient OtpToken { get; }
UserWalletContract.UserWalletContractClient UserWallet { get; }
UserWalletChangeLogContract.UserWalletChangeLogContractClient UserWalletChangeLog { get; }
ConfigurationContract.ConfigurationContractClient Configuration { get; }
CommissionContract.CommissionContractClient Commission { get; }
#endregion
#region PYMS

View File

@@ -1,5 +1,7 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Commands.WithdrawBalance;
public record WithdrawBalanceCommand : IRequest<Unit>
{
}
public long PayoutId { get; init; }
public int WithdrawalMethod { get; init; } // 0: Cash, 1: Diamond
public string? IbanNumber { get; init; }
}

View File

@@ -1,3 +1,5 @@
using CMSMicroservice.Protobuf.Protos.Commission;
namespace FrontOffice.BFF.Application.UserWalletCQ.Commands.WithdrawBalance;
public class WithdrawBalanceCommandHandler : IRequestHandler<WithdrawBalanceCommand, Unit>
{
@@ -10,7 +12,14 @@ public class WithdrawBalanceCommandHandler : IRequestHandler<WithdrawBalanceComm
public async Task<Unit> Handle(WithdrawBalanceCommand request, CancellationToken cancellationToken)
{
//TODO: Implement your business logic
return new Unit();
var withdrawRequest = new RequestWithdrawalRequest
{
PayoutId = request.PayoutId,
WithdrawalMethod = request.WithdrawalMethod,
IbanNumber = string.IsNullOrWhiteSpace(request.IbanNumber) ? null : request.IbanNumber
};
await _context.Commission.RequestWithdrawalAsync(withdrawRequest, cancellationToken: cancellationToken);
return Unit.Value;
}
}

View File

@@ -1,12 +1,21 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Commands.WithdrawBalance;
public class WithdrawBalanceCommandValidator : AbstractValidator<Unit>
public class WithdrawBalanceCommandValidator : AbstractValidator<WithdrawBalanceCommand>
{
public WithdrawBalanceCommandValidator()
{
RuleFor(x => x.PayoutId).GreaterThan(0);
RuleFor(x => x.WithdrawalMethod).InclusiveBetween(0, 1);
When(x => x.WithdrawalMethod == 0, () =>
{
RuleFor(x => x.IbanNumber)
.NotEmpty()
.MinimumLength(10)
.WithMessage("شماره شبا لازم است");
});
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<Unit>.CreateWithOptions((Unit)model, x => x.IncludeProperties(propertyName)));
var result = await ValidateAsync(ValidationContext<WithdrawBalanceCommand>.CreateWithOptions((WithdrawBalanceCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);

View File

@@ -1,5 +1,2 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetAllUserWalletChangeLog;
public record GetAllUserWalletChangeLogQuery : IRequest<GetAllUserWalletChangeLogResponseDto>
{
}
public record GetAllUserWalletChangeLogQuery(long? ReferenceId, bool? IsIncrease) : IRequest<GetAllUserWalletChangeLogResponseDto>;

View File

@@ -24,10 +24,12 @@ public class
{
Filter = new GetAllUserWalletChangeLogByFilterFilter()
{
UserId = _currentUserService.UserId.Value
UserId = _currentUserService.UserId.Value,
RefrenceId = request.ReferenceId.HasValue ? new Google.Protobuf.WellKnownTypes.Int64Value { Value = request.ReferenceId.Value } : null,
IsIncrease = request.IsIncrease.HasValue ? new Google.Protobuf.WellKnownTypes.BoolValue { Value = request.IsIncrease.Value } : null
}
}, cancellationToken: cancellationToken);
var finalResult= result.Adapt<GetAllUserWalletChangeLogResponseDto>();
return finalResult;
}
}
}

View File

@@ -1,12 +1,13 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetAllUserWalletChangeLog;
public class GetAllUserWalletChangeLogQueryValidator : AbstractValidator<Unit>
public class GetAllUserWalletChangeLogQueryValidator : AbstractValidator<GetAllUserWalletChangeLogQuery>
{
public GetAllUserWalletChangeLogQueryValidator()
{
RuleFor(x => x.ReferenceId).GreaterThan(0).When(x => x.ReferenceId.HasValue);
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<Unit>.CreateWithOptions((Unit)model, x => x.IncludeProperties(propertyName)));
var result = await ValidateAsync(ValidationContext<GetAllUserWalletChangeLogQuery>.CreateWithOptions((GetAllUserWalletChangeLogQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);

View File

@@ -3,7 +3,9 @@ public class GetUserWalletResponseDto
{
//موجودی
public long Balance { get; set; }
//موجودی تخفیف باشگاه
public long DiscountBalance { get; set; }
//موجودی شبکه
public long NetworkBalance { get; set; }
}
}

View File

@@ -0,0 +1,3 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetUserWithdrawals;
public record GetUserWithdrawalsQuery(int? Status) : IRequest<GetUserWithdrawalsResponseDto>;

View File

@@ -0,0 +1,44 @@
using CMSMicroservice.Protobuf.Protos.Commission;
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetUserWithdrawals;
public class GetUserWithdrawalsQueryHandler : IRequestHandler<GetUserWithdrawalsQuery, GetUserWithdrawalsResponseDto>
{
private readonly IApplicationContractContext _context;
private readonly ICurrentUserService _currentUserService;
public GetUserWithdrawalsQueryHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
{
_context = context;
_currentUserService = currentUserService;
}
public async Task<GetUserWithdrawalsResponseDto> Handle(GetUserWithdrawalsQuery request, CancellationToken cancellationToken)
{
var response = await _context.Commission.GetUserCommissionPayoutsAsync(new GetUserCommissionPayoutsRequest()
{
UserId = _currentUserService.UserId,
Status = request.Status.HasValue ? new Google.Protobuf.WellKnownTypes.Int32Value { Value = request.Status.Value } : null,
PageIndex = 1,
PageSize = 50
}, cancellationToken: cancellationToken);
var dto = new GetUserWithdrawalsResponseDto
{
MetaData = response.MetaData.Adapt<MetaData>(),
Models = response.Models
.Select(m => new UserWithdrawalModel
{
Id = m.Id,
WeekNumber = m.WeekNumber,
TotalAmount = m.TotalAmount,
Status = m.Status,
WithdrawalMethod = m.WithdrawalMethod?.Value,
IbanNumber = m.IbanNumber,
Created = m.Created.ToDateTime()
}).ToList()
};
return dto;
}
}

View File

@@ -0,0 +1,15 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetUserWithdrawals;
public class GetUserWithdrawalsQueryValidator : AbstractValidator<GetUserWithdrawalsQuery>
{
public GetUserWithdrawalsQueryValidator()
{
RuleFor(x => x.Status).InclusiveBetween(0, 3).When(x => x.Status.HasValue);
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetUserWithdrawalsQuery>.CreateWithOptions((GetUserWithdrawalsQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,17 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetUserWithdrawals;
public class GetUserWithdrawalsResponseDto
{
public MetaData MetaData { get; set; } = new();
public List<UserWithdrawalModel> Models { get; set; } = new();
}
public class UserWithdrawalModel
{
public long Id { get; set; }
public string WeekNumber { get; set; } = string.Empty;
public long TotalAmount { get; set; }
public int Status { get; set; }
public int? WithdrawalMethod { get; set; }
public string? IbanNumber { get; set; }
public DateTime Created { get; set; }
}

View File

@@ -0,0 +1,3 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetWithdrawalSettings;
public record GetWithdrawalSettingsQuery : IRequest<GetWithdrawalSettingsResponseDto>;

View File

@@ -0,0 +1,27 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetWithdrawalSettings;
public class GetWithdrawalSettingsQueryHandler : IRequestHandler<GetWithdrawalSettingsQuery, GetWithdrawalSettingsResponseDto>
{
private readonly IApplicationContractContext _context;
public GetWithdrawalSettingsQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetWithdrawalSettingsResponseDto> Handle(GetWithdrawalSettingsQuery request, CancellationToken cancellationToken)
{
const string key = "Commission.MinWithdrawalAmount";
var config = await _context.Configuration.GetConfigurationByKeyAsync(new CMSMicroservice.Protobuf.Protos.Configuration.GetConfigurationByKeyRequest()
{
Key = key
}, cancellationToken: cancellationToken);
long parsed = 0;
long.TryParse(config.Value, out parsed);
return new GetWithdrawalSettingsResponseDto
{
MinWithdrawalAmount = parsed
};
}
}

View File

@@ -0,0 +1,6 @@
namespace FrontOffice.BFF.Application.UserWalletCQ.Queries.GetWithdrawalSettings;
public class GetWithdrawalSettingsResponseDto
{
public long MinWithdrawalAmount { get; set; }
}

View File

@@ -8,6 +8,8 @@ using CMSMicroservice.Protobuf.Protos.ProductImages;
using CMSMicroservice.Protobuf.Protos.User;
using CMSMicroservice.Protobuf.Protos.UserAddress;
using CMSMicroservice.Protobuf.Protos.UserCarts;
using CMSMicroservice.Protobuf.Protos.Commission;
using CMSMicroservice.Protobuf.Protos.Configuration;
using CMSMicroservice.Protobuf.Protos.UserContract;
using CMSMicroservice.Protobuf.Protos.UserOrder;
using CMSMicroservice.Protobuf.Protos.UserWallet;
@@ -66,10 +68,12 @@ public class ApplicationContractContext : IApplicationContractContext
public OtpTokenContract.OtpTokenContractClient OtpToken => GetService<OtpTokenContract.OtpTokenContractClient>();
public UserWalletContract.UserWalletContractClient UserWallet => GetService<UserWalletContract.UserWalletContractClient>();
public UserWalletChangeLogContract.UserWalletChangeLogContractClient UserWalletChangeLog => GetService<UserWalletChangeLogContract.UserWalletChangeLogContractClient>();
public ConfigurationContract.ConfigurationContractClient Configuration => GetService<ConfigurationContract.ConfigurationContractClient>();
public CommissionContract.CommissionContractClient Commission => GetService<CommissionContract.CommissionContractClient>();
#endregion
#region PYMS
public TransactionContract.TransactionContractClient ZarinTransactions => GetService<TransactionContract.TransactionContractClient>();
#endregion
}
}

View File

@@ -3,6 +3,8 @@ using FrontOffice.BFF.Application.UserWalletCQ.Queries.GetAllUserWalletChangeLog
using FrontOffice.BFF.Application.UserWalletCQ.Queries.GetUserWallet;
using FrontOffice.BFF.Application.UserWalletCQ.Commands.TransferUserWalletBallance;
using FrontOffice.BFF.Application.UserWalletCQ.Commands.WithdrawBalance;
using FrontOffice.BFF.Application.UserWalletCQ.Queries.GetUserWithdrawals;
using FrontOffice.BFF.Application.UserWalletCQ.Queries.GetWithdrawalSettings;
using FrontOffice.BFF.UserWallet.Protobuf.Protos.UserWallet;
namespace FrontOffice.BFF.WebApi.Services;
@@ -14,9 +16,9 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<GetAllUserWalletChangeLogResponse> GetAllUserWalletChangeLog(Empty request, ServerCallContext context)
public override async Task<GetAllUserWalletChangeLogResponse> GetAllUserWalletChangeLog(GetAllUserWalletChangeLogRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllUserWalletChangeLogQuery, GetAllUserWalletChangeLogResponse>(context);
return await _dispatchRequestToCQRS.Handle<GetAllUserWalletChangeLogRequest, GetAllUserWalletChangeLogQuery, GetAllUserWalletChangeLogResponse>(request, context);
}
public override async Task<GetUserWalletResponse> GetUserWallet(Empty request, ServerCallContext context)
{
@@ -26,8 +28,16 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
{
return await _dispatchRequestToCQRS.Handle<TransferUserWalletBallanceCommand, Empty>(context);
}
public override async Task<Empty> WithdrawBalance(Empty request, ServerCallContext context)
public override async Task<Empty> WithdrawBalance(WithdrawBalanceRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<WithdrawBalanceCommand, Empty>(context);
return await _dispatchRequestToCQRS.Handle<WithdrawBalanceRequest, WithdrawBalanceCommand, Empty>(request, context);
}
public override async Task<GetUserWithdrawalsResponse> GetUserWithdrawals(GetUserWithdrawalsRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetUserWithdrawalsRequest, GetUserWithdrawalsQuery, GetUserWithdrawalsResponse>(request, context);
}
public override async Task<GetWithdrawalSettingsResponse> GetWithdrawalSettings(Empty request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetWithdrawalSettingsQuery, GetWithdrawalSettingsResponse>(context);
}
}

View File

@@ -3,7 +3,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.11</Version>
<Version>0.0.12</Version>
<PackageId>Foursat.FrontOffice.BFF.Category.Protobuf</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<DebugSymbols>False</DebugSymbols>
@@ -22,4 +22,13 @@
<ItemGroup>
<Protobuf Include="Protos\category.proto" ProtoRoot="Protos\" GrpcServices="Both" />
</ItemGroup>
<Target Name="PushToFoursatNuget" AfterTargets="Pack">
<PropertyGroup>
<NugetPackagePath>$(PackageOutputPath)$(PackageId).$(Version).nupkg</NugetPackagePath>
<PushCommand>dotnet nuget push **/*.nupkg --source https://git.afrino.co/api/packages/FourSat/nuget/index.json --api-key 061a5cb15517c6da39c16cfce8556c55ae104d0d --skip-duplicate &amp;&amp; del "$(NugetPackagePath)"</PushCommand>
</PropertyGroup>
<Exec Command="$(PushCommand)" />
</Target>
</Project>

View File

@@ -3,7 +3,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.15</Version>
<Version>0.0.16</Version>
<PackageId>Foursat.FrontOffice.BFF.Products.Protobuf</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<DebugSymbols>False</DebugSymbols>

View File

@@ -3,7 +3,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.13</Version>
<Version>0.0.14</Version>
<PackageId>Foursat.FrontOffice.BFF.UserWallet.Protobuf</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<DebugSymbols>False</DebugSymbols>

View File

@@ -12,10 +12,10 @@ option csharp_namespace = "FrontOffice.BFF.UserWallet.Protobuf.Protos.UserWallet
service UserWalletContract
{
rpc GetAllUserWalletChangeLog(google.protobuf.Empty) returns (GetAllUserWalletChangeLogResponse){
rpc GetAllUserWalletChangeLog(GetAllUserWalletChangeLogRequest) returns (GetAllUserWalletChangeLogResponse){
option (google.api.http) = {
get: "/GetAllUserWalletChangeLog"
post: "/GetAllUserWalletChangeLog"
body: "*"
};
};
rpc GetUserWallet(google.protobuf.Empty) returns (GetUserWalletResponse){
@@ -30,12 +30,23 @@ service UserWalletContract
body: "*"
};
};
rpc WithdrawBalance(google.protobuf.Empty) returns (google.protobuf.Empty){
rpc WithdrawBalance(WithdrawBalanceRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
post: "/WithdrawBalance"
body: "*"
};
};
rpc GetUserWithdrawals(GetUserWithdrawalsRequest) returns (GetUserWithdrawalsResponse){
option (google.api.http) = {
post: "/GetUserWithdrawals"
body: "*"
};
};
rpc GetWithdrawalSettings(google.protobuf.Empty) returns (GetWithdrawalSettingsResponse){
option (google.api.http) = {
get: "/GetWithdrawalSettings"
};
};
}
message GetAllUserWalletChangeLogResponse
{
@@ -56,6 +67,45 @@ message GetUserWalletResponse
{
int64 balance = 1;
int64 network_balance = 2;
int64 discount_balance = 3;
}
message WithdrawBalanceRequest
{
int64 payout_id = 1;
int32 withdrawal_method = 2; // 0: Cash, 1: Diamond
google.protobuf.StringValue iban_number = 3;
}
message GetAllUserWalletChangeLogRequest
{
google.protobuf.Int64Value reference_id = 1;
google.protobuf.BoolValue is_increase = 2;
}
message GetUserWithdrawalsRequest
{
google.protobuf.Int32Value status = 1;
}
message GetUserWithdrawalsResponse
{
MetaData meta_data = 1;
repeated UserWithdrawalModel models = 2;
}
message UserWithdrawalModel
{
int64 id = 1;
string week_number = 2;
int64 total_amount = 3;
int32 status = 4;
google.protobuf.Int32Value withdrawal_method = 5;
string iban_number = 6;
google.protobuf.Timestamp created = 7;
}
message GetWithdrawalSettingsResponse
{
int64 min_withdrawal_amount = 1;
}
message PaginationState
@@ -85,4 +135,4 @@ message GetUserWalletResponse
sfixed32 nanos = 2;
}