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