feat: Add Protobuf definitions for Network Membership service

- Introduced `networkmembership.proto` with RPC methods for retrieving user network tree, statistics, and position.
- Implemented HTTP annotations for gRPC transcoding in the service methods.
- Added support for Google API annotations in `annotations.proto` and `http.proto`.
- Created `ConfigureServices.cs` to register FluentValidation for the Protobuf services.
- Updated project file to include necessary dependencies for gRPC and Protobuf.
This commit is contained in:
masoodafar-web
2025-12-04 19:53:47 +03:30
parent 75e446f80f
commit 9a42060653
55 changed files with 3729 additions and 16 deletions

View File

@@ -0,0 +1,3 @@
namespace FrontOffice.BFF.Application.NetworkMembershipCQ.Queries.GetMyNetworkPosition;
public record GetMyNetworkPositionQuery : IRequest<GetMyNetworkPositionResponseDto>;

View File

@@ -0,0 +1,44 @@
using CMSMicroservice.Protobuf.Protos.NetworkMembership;
namespace FrontOffice.BFF.Application.NetworkMembershipCQ.Queries.GetMyNetworkPosition;
public class GetMyNetworkPositionQueryHandler : IRequestHandler<GetMyNetworkPositionQuery, GetMyNetworkPositionResponseDto>
{
private readonly IApplicationContractContext _context;
private readonly ICurrentUserService _currentUserService;
public GetMyNetworkPositionQueryHandler(
IApplicationContractContext context,
ICurrentUserService currentUserService)
{
_context = context;
_currentUserService = currentUserService;
}
public async Task<GetMyNetworkPositionResponseDto> Handle(GetMyNetworkPositionQuery request, CancellationToken cancellationToken)
{
var userId = _currentUserService.UserId ?? throw new UnauthorizedAccessException("User not authenticated");
var response = await _context.NetworkMemberships.GetUserNetworkAsync(
new GetUserNetworkRequest { UserId = userId },
cancellationToken: cancellationToken);
return new GetMyNetworkPositionResponseDto
{
UserId = response.UserId,
ParentId = response.ParentId ?? 0,
ParentName = response.ParentName ?? string.Empty,
Position = response.NetworkLeg switch
{
0 => "Left",
1 => "Right",
_ => "Root"
},
Level = response.NetworkLevel,
ReferralCode = response.ReferralCode ?? string.Empty,
JoinedAt = response.JoinedAt?.ToDateTime() ?? DateTime.UtcNow,
HasLeftChild = response.LeftChildId.HasValue,
HasRightChild = response.RightChildId.HasValue
};
}
}

View File

@@ -0,0 +1,49 @@
namespace FrontOffice.BFF.Application.NetworkMembershipCQ.Queries.GetMyNetworkPosition;
public class GetMyNetworkPositionResponseDto
{
/// <summary>
/// شناسه کاربر
/// </summary>
public long UserId { get; set; }
/// <summary>
/// شناسه والد
/// </summary>
public long ParentId { get; set; }
/// <summary>
/// نام والد
/// </summary>
public string ParentName { get; set; } = string.Empty;
/// <summary>
/// موقعیت در درخت (Left/Right)
/// </summary>
public string Position { get; set; } = string.Empty;
/// <summary>
/// سطح در درخت
/// </summary>
public int Level { get; set; }
/// <summary>
/// کد معرف
/// </summary>
public string ReferralCode { get; set; } = string.Empty;
/// <summary>
/// تاریخ عضویت
/// </summary>
public DateTime JoinedAt { get; set; }
/// <summary>
/// آیا فرزند چپ دارد؟
/// </summary>
public bool HasLeftChild { get; set; }
/// <summary>
/// آیا فرزند راست دارد؟
/// </summary>
public bool HasRightChild { get; set; }
}