feat: implement commission calculation strategy with ORM and SP options
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m43s

This commit is contained in:
masoodafar-web
2025-12-20 03:15:28 +03:30
parent 9864302bab
commit 25476ba120
18 changed files with 1687 additions and 21 deletions
@@ -0,0 +1,104 @@
using CMSMicroservice.Application.ClubMembershipCQ.Queries.GetAllClubMemberships;
using CMSMicroservice.Application.ClubMembershipCQ.Queries.GetClubStatistics;
using CMSMicroservice.Protobuf.Protos.ClubMembership;
using Google.Protobuf.WellKnownTypes;
using Mapster;
using System.Linq;
namespace CMSMicroservice.WebApi.Common.Mappings;
public class ClubMembershipProfile : IRegister
{
public void Register(TypeAdapterConfig config)
{
// =====================
// GetAllClubMemberships
// =====================
// GetAllClubMembershipsRequest -> GetAllClubMembershipsQuery
config.NewConfig<GetAllClubMembershipsRequest, GetAllClubMembershipsQuery>()
.MapWith(src => new GetAllClubMembershipsQuery
{
PaginationState = new Application.Common.Models.PaginationState
{
PageNumber = src.PageIndex > 0 ? src.PageIndex : 1,
PageSize = src.PageSize > 0 ? src.PageSize : 20
},
Filter = new GetAllClubMembershipsFilter
{
UserId = src.UserId,
IsActive = src.IsActive
}
});
// GetAllClubMembershipsResponseDto -> GetAllClubMembershipsResponse
config.NewConfig<GetAllClubMembershipsResponseDto, GetAllClubMembershipsResponse>()
.MapWith(src => new GetAllClubMembershipsResponse
{
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
{
CurrentPage = src.MetaData.CurrentPage,
PageSize = src.MetaData.PageSize,
TotalCount = src.MetaData.TotalCount,
TotalPage = src.MetaData.TotalPage
},
Models = { src.Models.Select(MapToModel) }
});
// =====================
// GetClubStatistics
// =====================
// GetClubStatisticsRequest -> GetClubStatisticsQuery
config.NewConfig<GetClubStatisticsRequest, GetClubStatisticsQuery>()
.MapWith(src => new GetClubStatisticsQuery());
// GetClubStatisticsResponseDto -> GetClubStatisticsResponse
config.NewConfig<GetClubStatisticsResponseDto, GetClubStatisticsResponse>()
.MapWith(src => new GetClubStatisticsResponse
{
TotalMembers = src.TotalMembers,
ActiveMembers = src.ActiveMembers,
InactiveMembers = src.InactiveMembers,
ExpiredMembers = src.ExpiredMembers,
ActivePercentage = src.ActivePercentage,
TotalRevenue = src.TotalRevenue,
AverageMembershipDurationDays = src.AverageMembershipDurationDays,
ExpiringSoonCount = src.ExpiringSoonCount,
PackageDistribution = { src.PackageDistribution.Select(p => new PackageLevelDistribution
{
PackageId = p.PackageId,
PackageName = p.PackageName ?? string.Empty,
MemberCount = p.MemberCount,
Percentage = p.Percentage
}) },
MonthlyTrend = { src.MonthlyTrend.Select(t => new MonthlyMembershipTrend
{
Month = t.Month ?? string.Empty,
Activations = t.Activations,
Expirations = t.Expirations,
NetChange = t.NetChange
}) }
});
}
private static ClubMembershipModel MapToModel(GetAllClubMembershipsResponseModel src)
{
return new ClubMembershipModel
{
Id = src.Id,
UserId = src.UserId,
UserName = src.UserName ?? string.Empty,
PackageId = 0, // Not available in current entity
PackageName = string.Empty, // Not available in current entity
ActivationCode = string.Empty, // Not available in current entity
ActivatedAt = src.ActivatedAt.HasValue
? Timestamp.FromDateTime(DateTime.SpecifyKind(src.ActivatedAt.Value, DateTimeKind.Utc))
: null,
ExpiresAt = null, // Not available in current entity
IsActive = src.IsActive,
IsExpired = false, // Calculate based on ExpiresAt if available
Created = Timestamp.FromDateTime(src.Created.UtcDateTime)
};
}
}
@@ -1,5 +1,6 @@
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkTree;
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetUserNetworkPosition;
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkStatistics;
using CMSMicroservice.Protobuf.Protos.NetworkMembership;
using CMSMicroservice.Domain.Enums;
@@ -9,6 +10,10 @@ public class NetworkMembershipProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
// GetNetworkStatisticsRequest -> GetNetworkStatisticsQuery
config.NewConfig<GetNetworkStatisticsRequest, GetNetworkStatisticsQuery>()
.MapWith(src => new GetNetworkStatisticsQuery());
// Request mapping
config.NewConfig<GetNetworkTreeRequest, GetNetworkTreeQuery>()
.Map(dest => dest.UserId, src => src.UserId)