feat: add Mapster mapping and update network tree request
All checks were successful
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 2m11s
All checks were successful
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 2m11s
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Version>0.0.142</Version>
|
<Version>0.0.145</Version>
|
||||||
<DebugType>None</DebugType>
|
<DebugType>None</DebugType>
|
||||||
<DebugSymbols>False</DebugSymbols>
|
<DebugSymbols>False</DebugSymbols>
|
||||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
<Target Name="PushToFoursatNuget" AfterTargets="Pack">
|
<Target Name="PushToFoursatNuget" AfterTargets="Pack">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<NugetPackagePath>$(PackageOutputPath)$(PackageId).$(Version).nupkg</NugetPackagePath>
|
<NugetPackagePath>$(PackageOutputPath)$(PackageId).$(Version).nupkg</NugetPackagePath>
|
||||||
<PushCommand>dotnet nuget push **/*.nupkg --source https://git.afrino.co/api/packages/FourSat/nuget/index.json --api-key 061a5cb15517c6da39c16cfce8556c55ae104d0d --skip-duplicate && del "$(NugetPackagePath)"</PushCommand>
|
<PushCommand>dotnet nuget push **/*.nupkg --source https://git.afrino.co/api/packages/FourSat/nuget/index.json --api-key 061a5cb15517c6da39c16cfce8556c55ae104d0d --skip-duplicate </PushCommand>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Exec Command="$(PushCommand)" />
|
<Exec Command="$(PushCommand)" />
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ message GetUserNetworkResponse
|
|||||||
// GetNetworkTree Query
|
// GetNetworkTree Query
|
||||||
message GetNetworkTreeRequest
|
message GetNetworkTreeRequest
|
||||||
{
|
{
|
||||||
int64 root_user_id = 1;
|
int64 user_id = 1;
|
||||||
google.protobuf.Int32Value max_depth = 2;
|
google.protobuf.Int32Value max_depth = 2;
|
||||||
google.protobuf.BoolValue only_active = 3;
|
google.protobuf.BoolValue only_active = 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<PackageReference Include="Grpc.Net.Client" Version="2.54.0" />
|
<PackageReference Include="Grpc.Net.Client" Version="2.54.0" />
|
||||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.22" />
|
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.22" />
|
||||||
<PackageReference Include="Hangfire.SqlServer" Version="1.8.22" />
|
<PackageReference Include="Hangfire.SqlServer" Version="1.8.22" />
|
||||||
|
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||||
|
|
||||||
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" />
|
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" />
|
||||||
<PackageReference Include="MediatR" Version="11.0.0" />
|
<PackageReference Include="MediatR" Version="11.0.0" />
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkTree;
|
||||||
|
using CMSMicroservice.Protobuf.Protos.NetworkMembership;
|
||||||
|
using CMSMicroservice.Domain.Enums;
|
||||||
|
|
||||||
|
namespace CMSMicroservice.WebApi.Common.Mappings;
|
||||||
|
|
||||||
|
public class NetworkMembershipProfile : IRegister
|
||||||
|
{
|
||||||
|
void IRegister.Register(TypeAdapterConfig config)
|
||||||
|
{
|
||||||
|
// Request mapping
|
||||||
|
config.NewConfig<GetNetworkTreeRequest, GetNetworkTreeQuery>()
|
||||||
|
.Map(dest => dest.UserId, src => src.UserId)
|
||||||
|
.Map(dest => dest.MaxDepth, src => src.MaxDepth != null && src.MaxDepth.Value > 0 ? src.MaxDepth.Value : 3);
|
||||||
|
|
||||||
|
// Response mapping: تبدیل درخت به لیست مسطح
|
||||||
|
config.NewConfig<NetworkTreeDto, GetNetworkTreeResponse>()
|
||||||
|
.MapWith(src => ConvertTreeToResponse(src));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GetNetworkTreeResponse ConvertTreeToResponse(NetworkTreeDto? treeDto)
|
||||||
|
{
|
||||||
|
var response = new GetNetworkTreeResponse();
|
||||||
|
|
||||||
|
if (treeDto == null)
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// تبدیل درخت به لیست مسطح
|
||||||
|
FlattenTree(treeDto, response.Nodes, null);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FlattenTree(NetworkTreeDto node, Google.Protobuf.Collections.RepeatedField<NetworkTreeNodeModel> nodesList, long? parentId)
|
||||||
|
{
|
||||||
|
var protoNode = new NetworkTreeNodeModel
|
||||||
|
{
|
||||||
|
UserId = node.UserId,
|
||||||
|
UserName = $"{node.FirstName} {node.LastName}".Trim(),
|
||||||
|
NetworkLeg = (int)(node.LegPosition ?? NetworkLeg.Left),
|
||||||
|
NetworkLevel = node.CurrentDepth,
|
||||||
|
IsActive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
if (parentId.HasValue)
|
||||||
|
{
|
||||||
|
protoNode.ParentId = parentId.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodesList.Add(protoNode);
|
||||||
|
|
||||||
|
// بازگشتی برای فرزندان
|
||||||
|
if (node.LeftChild != null)
|
||||||
|
{
|
||||||
|
FlattenTree(node.LeftChild, nodesList, node.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.RightChild != null)
|
||||||
|
{
|
||||||
|
FlattenTree(node.RightChild, nodesList, node.UserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,6 +41,8 @@ public class NetworkMembershipService : NetworkMembershipContract.NetworkMembers
|
|||||||
|
|
||||||
public override async Task<GetNetworkTreeResponse> GetNetworkTree(GetNetworkTreeRequest request, ServerCallContext context)
|
public override async Task<GetNetworkTreeResponse> GetNetworkTree(GetNetworkTreeRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var x=request.Adapt<GetNetworkTreeQuery>();
|
||||||
return await _dispatchRequestToCQRS.Handle<GetNetworkTreeRequest, GetNetworkTreeQuery, GetNetworkTreeResponse>(request, context);
|
return await _dispatchRequestToCQRS.Handle<GetNetworkTreeRequest, GetNetworkTreeQuery, GetNetworkTreeResponse>(request, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user