feat: Add gRPC clients and services for Club, Commission, Network, and Discount functionalities
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
using FrontOffice.BFF.NetworkMembership.Protobuf.Protos.NetworkMembership;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Service for Network Membership operations
|
||||
/// TODO: Connect to FrontOffice.BFF gRPC NetworkMembershipCQ
|
||||
/// Connected to FrontOffice.BFF gRPC NetworkMembershipCQ
|
||||
/// </summary>
|
||||
public class NetworkMembershipService
|
||||
{
|
||||
// TODO: Inject gRPC client when FrontOffice connects to BFF
|
||||
// private readonly NetworkMembershipContract.NetworkMembershipContractClient _client;
|
||||
private readonly NetworkMembershipContract.NetworkMembershipContractClient _client;
|
||||
|
||||
public NetworkMembershipService()
|
||||
public NetworkMembershipService(NetworkMembershipContract.NetworkMembershipContractClient client)
|
||||
{
|
||||
// TODO: Initialize gRPC client
|
||||
_client = client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -20,14 +22,93 @@ public class NetworkMembershipService
|
||||
/// </summary>
|
||||
public async Task<NetworkTreeDto> GetMyNetworkTreeAsync(int maxDepth = 3)
|
||||
{
|
||||
// TODO: Replace with actual gRPC call to BFF
|
||||
// var request = new GetMyNetworkTreeRequest { MaxDepth = maxDepth };
|
||||
// var response = await _client.GetMyNetworkTreeAsync(request);
|
||||
// return MapToDto(response);
|
||||
try
|
||||
{
|
||||
var request = new GetMyNetworkTreeRequest { MaxDepth = maxDepth };
|
||||
var response = await _client.GetMyNetworkTreeAsync(request);
|
||||
|
||||
return new NetworkTreeDto
|
||||
{
|
||||
RootNode = MapNodeFromProto(response.RootNode),
|
||||
TotalMembers = response.TotalMembers,
|
||||
CurrentDepth = response.CurrentDepth
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to mock data if backend is unavailable
|
||||
return CreateMockTree();
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(500); // Simulate network delay
|
||||
/// <summary>
|
||||
/// Get current user's network statistics
|
||||
/// Maps to: NetworkMembershipCQ.GetMyNetworkStatistics
|
||||
/// </summary>
|
||||
public async Task<NetworkStatisticsDto> GetMyNetworkStatisticsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _client.GetMyNetworkStatisticsAsync(new Empty());
|
||||
|
||||
return new NetworkStatisticsDto
|
||||
{
|
||||
LeftLegCount = response.LeftLegCount,
|
||||
RightLegCount = response.RightLegCount,
|
||||
TotalMembers = response.TotalMembers,
|
||||
TreeDepth = response.MaxDepth,
|
||||
WeakerLeg = response.WeakerLeg,
|
||||
LastMember = response.LastMember != null ? new LastMemberDto
|
||||
{
|
||||
UserId = response.LastMember.UserId,
|
||||
FullName = response.LastMember.FullName,
|
||||
Position = response.LastMember.Position,
|
||||
JoinedAt = DateTime.Now // TODO: Add JoinedAt to proto
|
||||
} : null
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to mock data if backend is unavailable
|
||||
return new NetworkStatisticsDto
|
||||
{
|
||||
LeftLegCount = 15,
|
||||
RightLegCount = 12,
|
||||
TotalMembers = 27,
|
||||
TreeDepth = 4,
|
||||
WeakerLeg = "Right",
|
||||
LastMember = new LastMemberDto
|
||||
{
|
||||
UserId = 28,
|
||||
FullName = "محمد رضایی",
|
||||
Position = "Left",
|
||||
JoinedAt = DateTime.Now.AddHours(-2)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Mock data with sample tree
|
||||
#region Helper Methods
|
||||
|
||||
private static NetworkNodeDto? MapNodeFromProto(NetworkNodeModel? node)
|
||||
{
|
||||
if (node == null) return null;
|
||||
|
||||
return new NetworkNodeDto
|
||||
{
|
||||
UserId = node.UserId,
|
||||
FullName = node.FullName,
|
||||
Mobile = node.Mobile,
|
||||
Avatar = node.Avatar,
|
||||
Position = node.Position,
|
||||
Level = node.Level,
|
||||
LeftChild = MapNodeFromProto(node.LeftChild),
|
||||
RightChild = MapNodeFromProto(node.RightChild)
|
||||
};
|
||||
}
|
||||
|
||||
private static NetworkTreeDto CreateMockTree()
|
||||
{
|
||||
return new NetworkTreeDto
|
||||
{
|
||||
CurrentDepth = 2,
|
||||
@@ -45,15 +126,7 @@ public class NetworkMembershipService
|
||||
FullName = "علی محمدی",
|
||||
Mobile = "09121234568",
|
||||
Position = "Left",
|
||||
Level = 1,
|
||||
LeftChild = new NetworkNodeDto
|
||||
{
|
||||
UserId = 4,
|
||||
FullName = "رضا احمدی",
|
||||
Mobile = "09121234570",
|
||||
Position = "Left",
|
||||
Level = 2
|
||||
}
|
||||
Level = 1
|
||||
},
|
||||
RightChild = new NetworkNodeDto
|
||||
{
|
||||
@@ -61,48 +134,11 @@ public class NetworkMembershipService
|
||||
FullName = "فاطمه حسینی",
|
||||
Mobile = "09121234569",
|
||||
Position = "Right",
|
||||
Level = 1,
|
||||
RightChild = new NetworkNodeDto
|
||||
{
|
||||
UserId = 5,
|
||||
FullName = "زهرا کریمی",
|
||||
Mobile = "09121234571",
|
||||
Position = "Right",
|
||||
Level = 2
|
||||
}
|
||||
Level = 1
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get current user's network statistics
|
||||
/// Maps to: NetworkMembershipCQ.GetMyNetworkStatistics
|
||||
/// </summary>
|
||||
public async Task<NetworkStatisticsDto> GetMyNetworkStatisticsAsync()
|
||||
{
|
||||
// TODO: Replace with actual gRPC call to BFF
|
||||
// var request = new GetMyNetworkStatisticsRequest();
|
||||
// var response = await _client.GetMyNetworkStatisticsAsync(request);
|
||||
// return MapToDto(response);
|
||||
|
||||
await Task.Delay(500); // Simulate network delay
|
||||
|
||||
// Mock statistics
|
||||
return new NetworkStatisticsDto
|
||||
{
|
||||
LeftLegCount = 15,
|
||||
RightLegCount = 12,
|
||||
TotalMembers = 27,
|
||||
TreeDepth = 4,
|
||||
WeakerLeg = "Right",
|
||||
LastMember = new LastMemberDto
|
||||
{
|
||||
UserId = 28,
|
||||
FullName = "محمد رضایی",
|
||||
Position = "Left",
|
||||
JoinedAt = DateTime.Now.AddHours(-2)
|
||||
}
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user