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:
@@ -7,16 +7,23 @@ using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetUserNetworkPosi
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkTree;
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkMembershipHistory;
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkStatistics;
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetMyNetworkTree;
|
||||
using Mapster;
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
|
||||
public class NetworkMembershipService : NetworkMembershipContract.NetworkMembershipContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
private readonly ISender _sender;
|
||||
|
||||
public NetworkMembershipService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
public NetworkMembershipService(
|
||||
IDispatchRequestToCQRS dispatchRequestToCQRS,
|
||||
ISender sender)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
public override async Task<Empty> JoinNetwork(JoinNetworkRequest request, ServerCallContext context)
|
||||
@@ -54,4 +61,134 @@ public class NetworkMembershipService : NetworkMembershipContract.NetworkMembers
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetNetworkStatisticsRequest, GetNetworkStatisticsQuery, GetNetworkStatisticsResponse>(request, context);
|
||||
}
|
||||
|
||||
// ============= Customer-specific Methods =============
|
||||
|
||||
public override async Task<GetMyNetworkTreeResponse> GetMyNetworkTree(GetMyNetworkTreeRequest request, ServerCallContext context)
|
||||
{
|
||||
// Use Customer-specific Query that gets UserId from ICurrentUserService
|
||||
var query = new GetMyNetworkTreeQuery
|
||||
{
|
||||
MaxDepth = request.MaxDepth > 0 ? request.MaxDepth : 3
|
||||
};
|
||||
|
||||
var tree = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
if (tree == null)
|
||||
{
|
||||
return new GetMyNetworkTreeResponse
|
||||
{
|
||||
RootNode = null,
|
||||
TotalMembers = 0,
|
||||
CurrentDepth = 0
|
||||
};
|
||||
}
|
||||
|
||||
// Convert NetworkTreeDto to NetworkTreeNodeModel
|
||||
var rootNode = ConvertToNodeModel(tree);
|
||||
|
||||
return new GetMyNetworkTreeResponse
|
||||
{
|
||||
RootNode = rootNode,
|
||||
TotalMembers = CountNodes(tree),
|
||||
CurrentDepth = tree.CurrentDepth
|
||||
};
|
||||
}
|
||||
|
||||
public override async Task<GetMyNetworkTreeResponse> GetSubordinateTree(GetSubordinateTreeRequest request, ServerCallContext context)
|
||||
{
|
||||
// Get tree for a specific subordinate user
|
||||
var query = new GetNetworkTreeQuery
|
||||
{
|
||||
UserId = request.TargetUserId,
|
||||
MaxDepth = request.MaxDepth > 0 ? request.MaxDepth : 3
|
||||
};
|
||||
|
||||
var tree = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
if (tree == null)
|
||||
{
|
||||
return new GetMyNetworkTreeResponse
|
||||
{
|
||||
RootNode = null,
|
||||
TotalMembers = 0,
|
||||
CurrentDepth = 0
|
||||
};
|
||||
}
|
||||
|
||||
var rootNode = ConvertToNodeModel(tree);
|
||||
|
||||
return new GetMyNetworkTreeResponse
|
||||
{
|
||||
RootNode = rootNode,
|
||||
TotalMembers = CountNodes(tree),
|
||||
CurrentDepth = tree.CurrentDepth
|
||||
};
|
||||
}
|
||||
|
||||
public override async Task<GetMyNetworkStatisticsResponse> GetMyNetworkStatistics(Google.Protobuf.WellKnownTypes.Empty request, ServerCallContext context)
|
||||
{
|
||||
// Get statistics for current user's network
|
||||
var query = new GetNetworkStatisticsQuery { UserId = 0 }; // Will use ICurrentUserService
|
||||
var stats = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
return stats.Adapt<GetMyNetworkStatisticsResponse>();
|
||||
}
|
||||
|
||||
// Helper methods for tree conversion
|
||||
private NetworkTreeNodeModel ConvertToNodeModel(NetworkTreeDto dto)
|
||||
{
|
||||
var node = new NetworkTreeNodeModel
|
||||
{
|
||||
UserId = dto.UserId,
|
||||
UserName = $"{dto.FirstName} {dto.LastName}".Trim(),
|
||||
FullName = $"{dto.FirstName} {dto.LastName}".Trim(),
|
||||
NetworkLeg = dto.LegPosition.HasValue ? (int)dto.LegPosition.Value : 0,
|
||||
NetworkLevel = dto.CurrentDepth,
|
||||
Level = dto.CurrentDepth,
|
||||
IsActive = dto.IsClubActive,
|
||||
IsClubActive = dto.IsClubActive,
|
||||
ReferralCode = dto.ReferralCode ?? "",
|
||||
Mobile = dto.Mobile ?? "",
|
||||
Position = dto.LegPosition.HasValue ? dto.LegPosition.Value.ToString() : "Root"
|
||||
};
|
||||
|
||||
if (dto.ClubActivatedAt.HasValue)
|
||||
{
|
||||
node.ClubActivatedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(
|
||||
DateTime.SpecifyKind(dto.ClubActivatedAt.Value, DateTimeKind.Utc));
|
||||
}
|
||||
|
||||
if (dto.UserCreated != null)
|
||||
{
|
||||
node.UserCreated = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(
|
||||
dto.UserCreated.UtcDateTime);
|
||||
}
|
||||
|
||||
if (dto.ActivationWeekDefinitionId.HasValue)
|
||||
{
|
||||
node.ActivationWeekDefinitionId = dto.ActivationWeekDefinitionId.Value;
|
||||
}
|
||||
|
||||
node.IsActivatedInTargetWeek = dto.IsActivatedInTargetWeek;
|
||||
|
||||
// Recursively convert children
|
||||
if (dto.LeftChild != null)
|
||||
{
|
||||
node.LeftChild = ConvertToNodeModel(dto.LeftChild);
|
||||
}
|
||||
|
||||
if (dto.RightChild != null)
|
||||
{
|
||||
node.RightChild = ConvertToNodeModel(dto.RightChild);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
private int CountNodes(NetworkTreeDto tree)
|
||||
{
|
||||
if (tree == null) return 0;
|
||||
return 1 + CountNodes(tree.LeftChild) + CountNodes(tree.RightChild);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user