feat: Add GetClubStatistics and GetNetworkStatistics APIs with corresponding request and response messages
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.0.140</Version>
|
||||
<Version>0.0.141</Version>
|
||||
<DebugType>None</DebugType>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||
|
||||
@@ -45,6 +45,11 @@ service ClubMembershipContract
|
||||
get: "/ClubMembership/GetHistory"
|
||||
};
|
||||
};
|
||||
rpc GetClubStatistics(GetClubStatisticsRequest) returns (GetClubStatisticsResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/ClubMembership/GetStatistics"
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// Activate Command
|
||||
@@ -164,3 +169,39 @@ message ClubMembershipHistoryModel
|
||||
string reason = 12;
|
||||
google.protobuf.Timestamp created = 13;
|
||||
}
|
||||
|
||||
// GetClubStatistics Query
|
||||
message GetClubStatisticsRequest
|
||||
{
|
||||
// Empty - returns overall club statistics
|
||||
}
|
||||
|
||||
message GetClubStatisticsResponse
|
||||
{
|
||||
int32 total_members = 1;
|
||||
int32 active_members = 2;
|
||||
int32 inactive_members = 3;
|
||||
int32 expired_members = 4;
|
||||
double active_percentage = 5;
|
||||
repeated PackageLevelDistribution package_distribution = 6;
|
||||
repeated MonthlyMembershipTrend monthly_trend = 7;
|
||||
int64 total_revenue = 8;
|
||||
double average_membership_duration_days = 9;
|
||||
int32 expiring_soon_count = 10; // Expiring in next 30 days
|
||||
}
|
||||
|
||||
message PackageLevelDistribution
|
||||
{
|
||||
int64 package_id = 1;
|
||||
string package_name = 2;
|
||||
int32 member_count = 3;
|
||||
double percentage = 4;
|
||||
}
|
||||
|
||||
message MonthlyMembershipTrend
|
||||
{
|
||||
string month = 1; // Format: "2025-11"
|
||||
int32 activations = 2;
|
||||
int32 expirations = 3;
|
||||
int32 net_change = 4;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,46 @@ service CommissionContract
|
||||
get: "/Commission/GetUserWeeklyBalances"
|
||||
};
|
||||
};
|
||||
rpc GetAllWeeklyPools(GetAllWeeklyPoolsRequest) returns (GetAllWeeklyPoolsResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/Commission/GetAllWeeklyPools"
|
||||
};
|
||||
};
|
||||
rpc GetWithdrawalRequests(GetWithdrawalRequestsRequest) returns (GetWithdrawalRequestsResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/Commission/GetWithdrawalRequests"
|
||||
};
|
||||
};
|
||||
rpc ApproveWithdrawal(ApproveWithdrawalRequest) returns (google.protobuf.Empty){
|
||||
option (google.api.http) = {
|
||||
post: "/Commission/ApproveWithdrawal"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
rpc RejectWithdrawal(RejectWithdrawalRequest) returns (google.protobuf.Empty){
|
||||
option (google.api.http) = {
|
||||
post: "/Commission/RejectWithdrawal"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
|
||||
// Worker Control APIs
|
||||
rpc TriggerWeeklyCalculation(TriggerWeeklyCalculationRequest) returns (TriggerWeeklyCalculationResponse){
|
||||
option (google.api.http) = {
|
||||
post: "/Commission/TriggerCalculation"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
rpc GetWorkerStatus(GetWorkerStatusRequest) returns (GetWorkerStatusResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/Commission/GetWorkerStatus"
|
||||
};
|
||||
};
|
||||
rpc GetWorkerExecutionLogs(GetWorkerExecutionLogsRequest) returns (GetWorkerExecutionLogsResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/Commission/GetWorkerLogs"
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// ============ Commands ============
|
||||
@@ -105,6 +145,20 @@ message ProcessWithdrawalRequest
|
||||
google.protobuf.StringValue reason = 3; // Required for rejection
|
||||
}
|
||||
|
||||
// ApproveWithdrawal Command
|
||||
message ApproveWithdrawalRequest
|
||||
{
|
||||
int64 payout_id = 1;
|
||||
google.protobuf.StringValue notes = 2; // Optional admin notes
|
||||
}
|
||||
|
||||
// RejectWithdrawal Command
|
||||
message RejectWithdrawalRequest
|
||||
{
|
||||
int64 payout_id = 1;
|
||||
string reason = 2; // Required reason for rejection
|
||||
}
|
||||
|
||||
// ============ Queries ============
|
||||
|
||||
// GetWeeklyCommissionPool Query
|
||||
@@ -218,3 +272,135 @@ message UserWeeklyBalanceModel
|
||||
bool is_expired = 9;
|
||||
google.protobuf.Timestamp created = 10;
|
||||
}
|
||||
|
||||
// GetAllWeeklyPools Query
|
||||
message GetAllWeeklyPoolsRequest
|
||||
{
|
||||
google.protobuf.StringValue from_week = 1; // Format: "YYYY-Www" (optional)
|
||||
google.protobuf.StringValue to_week = 2; // Format: "YYYY-Www" (optional)
|
||||
google.protobuf.BoolValue only_calculated = 3; // Only show calculated pools
|
||||
int32 page_index = 4;
|
||||
int32 page_size = 5;
|
||||
}
|
||||
|
||||
message GetAllWeeklyPoolsResponse
|
||||
{
|
||||
messages.MetaData meta_data = 1;
|
||||
repeated WeeklyCommissionPoolModel models = 2;
|
||||
}
|
||||
|
||||
message WeeklyCommissionPoolModel
|
||||
{
|
||||
int64 id = 1;
|
||||
string week_number = 2;
|
||||
int64 total_pool_amount = 3;
|
||||
int32 total_balances = 4;
|
||||
int64 value_per_balance = 5;
|
||||
bool is_calculated = 6;
|
||||
google.protobuf.Timestamp calculated_at = 7;
|
||||
google.protobuf.Timestamp created = 8;
|
||||
}
|
||||
|
||||
// GetWithdrawalRequests Query
|
||||
message GetWithdrawalRequestsRequest
|
||||
{
|
||||
google.protobuf.Int32Value status = 1; // CommissionPayoutStatus enum: Pending=1, Approved=2, Rejected=3
|
||||
google.protobuf.Int64Value user_id = 2;
|
||||
google.protobuf.StringValue week_number = 3;
|
||||
int32 page_index = 4;
|
||||
int32 page_size = 5;
|
||||
}
|
||||
|
||||
message GetWithdrawalRequestsResponse
|
||||
{
|
||||
messages.MetaData meta_data = 1;
|
||||
repeated WithdrawalRequestModel models = 2;
|
||||
}
|
||||
|
||||
// ============ Worker Control APIs ============
|
||||
|
||||
// TriggerWeeklyCalculation Command
|
||||
message TriggerWeeklyCalculationRequest
|
||||
{
|
||||
string week_number = 1; // Format: "YYYY-Www" (e.g., "2025-W48")
|
||||
bool force_recalculate = 2; // اگر true باشد، محاسبات قبلی را حذف و دوباره محاسبه میکند
|
||||
bool skip_balances = 3; // Skip balance calculation (only pool and payouts)
|
||||
bool skip_pool = 4; // Skip pool calculation (only balances and payouts)
|
||||
bool skip_payouts = 5; // Skip payout processing (only balances and pool)
|
||||
}
|
||||
|
||||
message TriggerWeeklyCalculationResponse
|
||||
{
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
string execution_id = 3; // Unique ID for tracking this execution
|
||||
google.protobuf.Timestamp started_at = 4;
|
||||
}
|
||||
|
||||
// GetWorkerStatus Query
|
||||
message GetWorkerStatusRequest
|
||||
{
|
||||
// Empty - returns current worker status
|
||||
}
|
||||
|
||||
message GetWorkerStatusResponse
|
||||
{
|
||||
bool is_running = 1;
|
||||
bool is_enabled = 2;
|
||||
google.protobuf.StringValue current_execution_id = 3;
|
||||
google.protobuf.StringValue current_week_number = 4;
|
||||
google.protobuf.StringValue current_step = 5; // "Balances" | "Pool" | "Payouts" | "Idle"
|
||||
google.protobuf.Timestamp last_run_at = 6;
|
||||
google.protobuf.Timestamp next_scheduled_run = 7;
|
||||
int32 total_executions = 8;
|
||||
int32 successful_executions = 9;
|
||||
int32 failed_executions = 10;
|
||||
}
|
||||
|
||||
// GetWorkerExecutionLogs Query
|
||||
message GetWorkerExecutionLogsRequest
|
||||
{
|
||||
google.protobuf.StringValue week_number = 1; // Filter by week
|
||||
google.protobuf.StringValue execution_id = 2; // Filter by specific execution
|
||||
google.protobuf.BoolValue success_only = 3; // Show only successful runs
|
||||
google.protobuf.BoolValue failed_only = 4; // Show only failed runs
|
||||
int32 page_index = 5;
|
||||
int32 page_size = 6;
|
||||
}
|
||||
|
||||
message GetWorkerExecutionLogsResponse
|
||||
{
|
||||
messages.MetaData meta_data = 1;
|
||||
repeated WorkerExecutionLogModel models = 2;
|
||||
}
|
||||
|
||||
message WorkerExecutionLogModel
|
||||
{
|
||||
string execution_id = 1;
|
||||
string week_number = 2;
|
||||
string step = 3; // "Balances" | "Pool" | "Payouts" | "Full"
|
||||
bool success = 4;
|
||||
google.protobuf.StringValue error_message = 5;
|
||||
google.protobuf.Timestamp started_at = 6;
|
||||
google.protobuf.Timestamp completed_at = 7;
|
||||
int64 duration_ms = 8; // Duration in milliseconds
|
||||
int32 records_processed = 9;
|
||||
google.protobuf.StringValue details = 10; // JSON or text details
|
||||
}
|
||||
|
||||
message WithdrawalRequestModel
|
||||
{
|
||||
int64 id = 1;
|
||||
int64 user_id = 2;
|
||||
string user_name = 3;
|
||||
string week_number = 4;
|
||||
int64 amount = 5;
|
||||
int32 status = 6; // CommissionPayoutStatus enum
|
||||
int32 withdrawal_method = 7; // WithdrawalMethod enum
|
||||
string iban_number = 8;
|
||||
google.protobuf.Timestamp requested_at = 9;
|
||||
google.protobuf.Timestamp processed_at = 10;
|
||||
string processed_by = 11;
|
||||
string reason = 12;
|
||||
google.protobuf.Timestamp created = 13;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ service NetworkMembershipContract
|
||||
get: "/NetworkMembership/GetHistory"
|
||||
};
|
||||
};
|
||||
rpc GetNetworkStatistics(GetNetworkStatisticsRequest) returns (GetNetworkStatisticsResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/NetworkMembership/GetStatistics"
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// JoinNetwork Command
|
||||
@@ -150,3 +155,46 @@ message NetworkMembershipHistoryModel
|
||||
string reason = 11;
|
||||
google.protobuf.Timestamp created = 12;
|
||||
}
|
||||
|
||||
// GetNetworkStatistics Query
|
||||
message GetNetworkStatisticsRequest
|
||||
{
|
||||
// Empty - returns overall network statistics
|
||||
}
|
||||
|
||||
message GetNetworkStatisticsResponse
|
||||
{
|
||||
int32 total_members = 1;
|
||||
int32 active_members = 2;
|
||||
int32 left_leg_count = 3;
|
||||
int32 right_leg_count = 4;
|
||||
double left_percentage = 5;
|
||||
double right_percentage = 6;
|
||||
double average_depth = 7;
|
||||
int32 max_depth = 8;
|
||||
repeated LevelDistribution level_distribution = 9;
|
||||
repeated MonthlyGrowth monthly_growth = 10;
|
||||
repeated TopNetworkUser top_users = 11;
|
||||
}
|
||||
|
||||
message LevelDistribution
|
||||
{
|
||||
int32 level = 1;
|
||||
int32 count = 2;
|
||||
}
|
||||
|
||||
message MonthlyGrowth
|
||||
{
|
||||
string month = 1; // Format: "2025-11" or Persian month name
|
||||
int32 new_members = 2;
|
||||
}
|
||||
|
||||
message TopNetworkUser
|
||||
{
|
||||
int32 rank = 1;
|
||||
int64 user_id = 2;
|
||||
string user_name = 3;
|
||||
int32 total_children = 4;
|
||||
int32 left_count = 5;
|
||||
int32 right_count = 6;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using CMSMicroservice.Application.ClubMembershipCQ.Commands.AssignClubFeature;
|
||||
using CMSMicroservice.Application.ClubMembershipCQ.Queries.GetClubMembership;
|
||||
using CMSMicroservice.Application.ClubMembershipCQ.Queries.GetAllClubMemberships;
|
||||
using CMSMicroservice.Application.ClubMembershipCQ.Queries.GetClubMembershipHistory;
|
||||
using CMSMicroservice.Application.ClubMembershipCQ.Queries.GetClubStatistics;
|
||||
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
|
||||
@@ -47,4 +48,9 @@ public class ClubMembershipService : ClubMembershipContract.ClubMembershipContra
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetClubMembershipHistoryRequest, GetClubMembershipHistoryQuery, GetClubMembershipHistoryResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetClubStatisticsResponse> GetClubStatistics(GetClubStatisticsRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetClubStatisticsRequest, GetClubStatisticsQuery, GetClubStatisticsResponse>(request, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,17 @@ using CMSMicroservice.Application.CommissionCQ.Commands.CalculateWeeklyCommissio
|
||||
using CMSMicroservice.Application.CommissionCQ.Commands.ProcessUserPayouts;
|
||||
using CMSMicroservice.Application.CommissionCQ.Commands.RequestWithdrawal;
|
||||
using CMSMicroservice.Application.CommissionCQ.Commands.ProcessWithdrawal;
|
||||
using CMSMicroservice.Application.CommissionCQ.Commands.ApproveWithdrawal;
|
||||
using CMSMicroservice.Application.CommissionCQ.Commands.RejectWithdrawal;
|
||||
using CMSMicroservice.Application.CommissionCQ.Commands.TriggerWeeklyCalculation;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetWeeklyCommissionPool;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetUserCommissionPayouts;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetCommissionPayoutHistory;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetUserWeeklyBalances;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetAllWeeklyPools;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetWithdrawalRequests;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetWorkerStatus;
|
||||
using CMSMicroservice.Application.CommissionCQ.Queries.GetWorkerExecutionLogs;
|
||||
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
|
||||
@@ -67,4 +74,40 @@ public class CommissionService : CommissionContract.CommissionContractBase
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetUserWeeklyBalancesRequest, GetUserWeeklyBalancesQuery, GetUserWeeklyBalancesResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetAllWeeklyPoolsResponse> GetAllWeeklyPools(GetAllWeeklyPoolsRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllWeeklyPoolsRequest, GetAllWeeklyPoolsQuery, GetAllWeeklyPoolsResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetWithdrawalRequestsResponse> GetWithdrawalRequests(GetWithdrawalRequestsRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetWithdrawalRequestsRequest, GetWithdrawalRequestsQuery, GetWithdrawalRequestsResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<Empty> ApproveWithdrawal(ApproveWithdrawalRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<ApproveWithdrawalRequest, ApproveWithdrawalCommand>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<Empty> RejectWithdrawal(RejectWithdrawalRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<RejectWithdrawalRequest, RejectWithdrawalCommand>(request, context);
|
||||
}
|
||||
|
||||
// Worker Control APIs
|
||||
public override async Task<TriggerWeeklyCalculationResponse> TriggerWeeklyCalculation(TriggerWeeklyCalculationRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<TriggerWeeklyCalculationRequest, TriggerWeeklyCalculationCommand, TriggerWeeklyCalculationResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetWorkerStatusResponse> GetWorkerStatus(GetWorkerStatusRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetWorkerStatusRequest, GetWorkerStatusQuery, GetWorkerStatusResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetWorkerExecutionLogsResponse> GetWorkerExecutionLogs(GetWorkerExecutionLogsRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetWorkerExecutionLogsRequest, GetWorkerExecutionLogsQuery, GetWorkerExecutionLogsResponse>(request, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using CMSMicroservice.Application.NetworkMembershipCQ.Commands.RemoveFromNetwork
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetUserNetworkPosition;
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkTree;
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkMembershipHistory;
|
||||
using CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkStatistics;
|
||||
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
|
||||
@@ -47,4 +48,9 @@ public class NetworkMembershipService : NetworkMembershipContract.NetworkMembers
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetNetworkMembershipHistoryRequest, GetNetworkMembershipHistoryQuery, GetNetworkMembershipHistoryResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetNetworkStatisticsResponse> GetNetworkStatistics(GetNetworkStatisticsRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetNetworkStatisticsRequest, GetNetworkStatisticsQuery, GetNetworkStatisticsResponse>(request, context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user