feat: Implement customer profile and referral queries
- Add GetCustomerProfileResponseDto for retrieving customer profile information. - Create GetCustomerReferralsQuery and GetCustomerReferralsQueryHandler to fetch customer referrals with pagination and filtering options. - Introduce GetCustomerReferralsResponseDto to structure the response for customer referrals. - Implement GetCustomerSettingsQuery and GetCustomerSettingsQueryHandler to retrieve user settings. - Add GetCustomerOrder and GetCustomerOrderQueryHandler for fetching specific customer orders. - Create GetCustomerOrderHistoryQuery and GetCustomerOrderHistoryQueryHandler to retrieve order history with filtering options. - Implement GetCustomerOrdersQuery and GetCustomerOrdersQueryHandler for fetching multiple customer orders with filters. - Add GetCustomerWalletChangeLogQuery and GetCustomerWalletChangeLogQueryHandler for retrieving wallet change logs. - Implement GetCustomerWithdrawalSettingsQuery and GetCustomerWithdrawalSettingsQueryHandler for fetching withdrawal settings. - Create GetCustomerWithdrawalsQuery and GetCustomerWithdrawalsQueryHandler to retrieve customer withdrawal requests.
This commit is contained in:
@@ -5,14 +5,19 @@ using CMSMicroservice.Application.UserWalletCQ.Commands.UpdateUserWallet;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Commands.DeleteUserWallet;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletChangeLog;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawals;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawalSettings;
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
public class UserWalletService : UserWalletContract.UserWalletContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
private readonly ISender _sender;
|
||||
|
||||
public UserWalletService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
public UserWalletService(IDispatchRequestToCQRS dispatchRequestToCQRS, ISender sender)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
_sender = sender;
|
||||
}
|
||||
public override async Task<CreateNewUserWalletResponse> CreateNewUserWallet(CreateNewUserWalletRequest request, ServerCallContext context)
|
||||
{
|
||||
@@ -39,53 +44,56 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
||||
|
||||
public override async Task<GetCustomerWalletResponse> GetCustomerWallet(Google.Protobuf.WellKnownTypes.Empty request, ServerCallContext context)
|
||||
{
|
||||
// Mock response for customer wallet
|
||||
// Use GetUserWallet with Id=0 to automatically use current user from JWT
|
||||
var walletQuery = new GetUserWalletQuery { Id = 0 };
|
||||
var wallet = await _sender.Send(walletQuery, context.CancellationToken);
|
||||
|
||||
return new GetCustomerWalletResponse
|
||||
{
|
||||
Balance = 150000,
|
||||
NetworkBalance = 75000,
|
||||
DiscountBalance = 25000
|
||||
Balance = wallet.Balance,
|
||||
NetworkBalance = wallet.NetworkBalance,
|
||||
DiscountBalance = wallet.DiscountBalance
|
||||
};
|
||||
}
|
||||
|
||||
public override async Task<GetCustomerWalletChangeLogResponse> GetCustomerWalletChangeLog(GetCustomerWalletChangeLogRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock response for wallet change log
|
||||
return new GetCustomerWalletChangeLogResponse
|
||||
var query = new GetCustomerWalletChangeLogQuery
|
||||
{
|
||||
ReferenceId = request.ReferenceId,
|
||||
IsIncrease = request.IsIncrease
|
||||
};
|
||||
|
||||
var changeLogs = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetCustomerWalletChangeLogResponse
|
||||
{
|
||||
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
|
||||
{
|
||||
CurrentPage = 1,
|
||||
TotalPage = 1,
|
||||
PageSize = 10,
|
||||
TotalCount = 3,
|
||||
PageSize = changeLogs.Count,
|
||||
TotalCount = changeLogs.Count,
|
||||
HasPrevious = false,
|
||||
HasNext = false
|
||||
},
|
||||
Models =
|
||||
{
|
||||
new CustomerWalletChangeLogModel
|
||||
{
|
||||
CurrentBalance = 150000,
|
||||
ChangeValue = 50000,
|
||||
CurrentNetworkBalance = 75000,
|
||||
ChangeNerworkValue = 25000,
|
||||
IsIncrease = true,
|
||||
RefrenceId = 123,
|
||||
CreatedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-1))
|
||||
},
|
||||
new CustomerWalletChangeLogModel
|
||||
{
|
||||
CurrentBalance = 100000,
|
||||
ChangeValue = -20000,
|
||||
CurrentNetworkBalance = 50000,
|
||||
ChangeNerworkValue = -10000,
|
||||
IsIncrease = false,
|
||||
RefrenceId = 124,
|
||||
CreatedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-2))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var log in changeLogs)
|
||||
{
|
||||
response.Models.Add(new CustomerWalletChangeLogModel
|
||||
{
|
||||
CurrentBalance = log.CurrentBalance,
|
||||
ChangeValue = log.ChangeValue,
|
||||
CurrentNetworkBalance = log.CurrentNetworkBalance,
|
||||
ChangeNerworkValue = log.ChangeNerworkValue,
|
||||
IsIncrease = log.IsIncrease,
|
||||
RefrenceId = log.RefrenceId,
|
||||
CreatedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.SpecifyKind(log.Created, DateTimeKind.Utc))
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<Google.Protobuf.WellKnownTypes.Empty> CustomerWithdrawBalance(CustomerWithdrawBalanceRequest request, ServerCallContext context)
|
||||
@@ -96,41 +104,52 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
||||
|
||||
public override async Task<GetCustomerWithdrawalsResponse> GetCustomerWithdrawals(GetCustomerWithdrawalsRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock response for customer withdrawals
|
||||
return new GetCustomerWithdrawalsResponse
|
||||
var query = new GetCustomerWithdrawalsQuery
|
||||
{
|
||||
Status = request.Status
|
||||
};
|
||||
|
||||
var withdrawals = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetCustomerWithdrawalsResponse
|
||||
{
|
||||
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
|
||||
{
|
||||
CurrentPage = 1,
|
||||
TotalPage = 1,
|
||||
PageSize = 10,
|
||||
TotalCount = 1,
|
||||
PageSize = withdrawals.Count,
|
||||
TotalCount = withdrawals.Count,
|
||||
HasPrevious = false,
|
||||
HasNext = false
|
||||
},
|
||||
Models =
|
||||
{
|
||||
new CustomerWithdrawalModel
|
||||
{
|
||||
Id = 1,
|
||||
WeekDefinitionId = 1,
|
||||
WeekDisplayName = "هفته 1 - دی 1403",
|
||||
TotalAmount = 50000,
|
||||
Status = 1, // 0: Pending, 1: Approved, 2: Rejected
|
||||
WithdrawalMethod = 0, // 0: Cash, 1: Diamond
|
||||
IbanNumber = "IR123456789",
|
||||
Created = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-3))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var withdrawal in withdrawals)
|
||||
{
|
||||
response.Models.Add(new CustomerWithdrawalModel
|
||||
{
|
||||
Id = withdrawal.Id,
|
||||
WeekDefinitionId = withdrawal.WeekDefinitionId,
|
||||
WeekDisplayName = withdrawal.WeekDisplayName,
|
||||
TotalAmount = withdrawal.TotalAmount,
|
||||
Status = withdrawal.Status,
|
||||
WithdrawalMethod = withdrawal.WithdrawalMethod,
|
||||
IbanNumber = withdrawal.IbanNumber,
|
||||
Created = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.SpecifyKind(withdrawal.Created, DateTimeKind.Utc))
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<GetCustomerWithdrawalSettingsResponse> GetCustomerWithdrawalSettings(Google.Protobuf.WellKnownTypes.Empty request, ServerCallContext context)
|
||||
{
|
||||
// Mock response for withdrawal settings
|
||||
var query = new GetCustomerWithdrawalSettingsQuery();
|
||||
var settings = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
return new GetCustomerWithdrawalSettingsResponse
|
||||
{
|
||||
MinWithdrawalAmount = 50000 // Minimum 50,000 for withdrawal
|
||||
MinWithdrawalAmount = settings.MinWithdrawalAmount
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user