This commit is contained in:
masoodafar-web
2025-12-02 03:32:26 +03:30
parent 6cd29e8b26
commit c9dab944fa
56 changed files with 1181 additions and 710 deletions
@@ -17,6 +17,7 @@ service ClubMembershipContract
rpc GetClubMembership(GetClubMembershipRequest) returns (GetClubMembershipResponse);
rpc GetAllClubMemberships(GetAllClubMembershipsRequest) returns (GetAllClubMembershipsResponse);
rpc GetClubMembershipHistory(GetClubMembershipHistoryRequest) returns (GetClubMembershipHistoryResponse);
rpc GetClubStatistics(GetClubStatisticsRequest) returns (GetClubStatisticsResponse);
}
// Activate Command
@@ -136,3 +137,40 @@ message ClubMembershipHistoryModel
string reason = 12;
google.protobuf.Timestamp created = 13;
}
// GetClubStatistics Query
message GetClubStatisticsRequest
{
// Empty - returns overall 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;
}
message PackageLevelDistribution
{
int64 package_id = 1;
string package_name = 2;
int32 member_count = 3;
double percentage = 4;
}
message MonthlyMembershipTrend
{
string month = 1;
int32 activations = 2;
int32 expirations = 3;
int32 net_change = 4;
}
@@ -20,6 +20,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.2.2" />
<PackageReference Include="Google.Api.CommonProtos" Version="2.10.0" />
</ItemGroup>
<ItemGroup>
@@ -12,21 +12,42 @@ option csharp_namespace = "BackOffice.BFF.Commission.Protobuf";
service CommissionContract
{
// Commands
rpc CalculateWeeklyBalances(CalculateWeeklyBalancesRequest) returns (google.protobuf.Empty);
rpc CalculateWeeklyCommissionPool(CalculateWeeklyCommissionPoolRequest) returns (google.protobuf.Empty);
rpc ProcessUserPayouts(ProcessUserPayoutsRequest) returns (google.protobuf.Empty);
rpc RequestWithdrawal(RequestWithdrawalRequest) returns (google.protobuf.Empty);
rpc ProcessWithdrawal(ProcessWithdrawalRequest) returns (ProcessWithdrawalResponse);
rpc ApproveWithdrawal(ApproveWithdrawalRequest) returns (ApproveWithdrawalResponse);
rpc RejectWithdrawal(RejectWithdrawalRequest) returns (RejectWithdrawalResponse);
rpc CalculateWeeklyBalances(CalculateWeeklyBalancesRequest) returns (google.protobuf.Empty){
};
rpc CalculateWeeklyCommissionPool(CalculateWeeklyCommissionPoolRequest) returns (google.protobuf.Empty){
};
rpc ProcessUserPayouts(ProcessUserPayoutsRequest) returns (google.protobuf.Empty){
};
rpc RequestWithdrawal(RequestWithdrawalRequest) returns (google.protobuf.Empty){
};
rpc ProcessWithdrawal(ProcessWithdrawalRequest) returns (google.protobuf.Empty){
};
// Queries
rpc GetWeeklyCommissionPool(GetWeeklyCommissionPoolRequest) returns (GetWeeklyCommissionPoolResponse);
rpc GetUserCommissionPayouts(GetUserCommissionPayoutsRequest) returns (GetUserCommissionPayoutsResponse);
rpc GetCommissionPayoutHistory(GetCommissionPayoutHistoryRequest) returns (GetCommissionPayoutHistoryResponse);
rpc GetUserWeeklyBalances(GetUserWeeklyBalancesRequest) returns (GetUserWeeklyBalancesResponse);
rpc GetAllWeeklyPools(GetAllWeeklyPoolsRequest) returns (GetAllWeeklyPoolsResponse);
rpc GetWithdrawalRequests(GetWithdrawalRequestsRequest) returns (GetWithdrawalRequestsResponse);
rpc GetWeeklyCommissionPool(GetWeeklyCommissionPoolRequest) returns (GetWeeklyCommissionPoolResponse){
};
rpc GetUserCommissionPayouts(GetUserCommissionPayoutsRequest) returns (GetUserCommissionPayoutsResponse){
};
rpc GetCommissionPayoutHistory(GetCommissionPayoutHistoryRequest) returns (GetCommissionPayoutHistoryResponse){
};
rpc GetUserWeeklyBalances(GetUserWeeklyBalancesRequest) returns (GetUserWeeklyBalancesResponse){
};
rpc GetAllWeeklyPools(GetAllWeeklyPoolsRequest) returns (GetAllWeeklyPoolsResponse){
};
rpc GetWithdrawalRequests(GetWithdrawalRequestsRequest) returns (GetWithdrawalRequestsResponse){
};
rpc ApproveWithdrawal(ApproveWithdrawalRequest) returns (google.protobuf.Empty){
};
rpc RejectWithdrawal(RejectWithdrawalRequest) returns (google.protobuf.Empty){
};
// Worker Control APIs
rpc TriggerWeeklyCalculation(TriggerWeeklyCalculationRequest) returns (TriggerWeeklyCalculationResponse){
};
rpc GetWorkerStatus(GetWorkerStatusRequest) returns (GetWorkerStatusResponse){
};
rpc GetWorkerExecutionLogs(GetWorkerExecutionLogsRequest) returns (GetWorkerExecutionLogsResponse){
};
}
// ============ Commands ============
@@ -62,41 +83,23 @@ message RequestWithdrawalRequest
// ProcessWithdrawal Command
message ProcessWithdrawalRequest
{
int64 withdrawal_id = 1;
string transaction_id = 2;
string admin_note = 3;
}
message ProcessWithdrawalResponse
{
bool success = 1;
string message = 2;
int64 payout_id = 1;
bool is_approved = 2;
google.protobuf.StringValue reason = 3; // Required for rejection
}
// ApproveWithdrawal Command
message ApproveWithdrawalRequest
{
int64 withdrawal_id = 1;
string admin_note = 2;
}
message ApproveWithdrawalResponse
{
bool success = 1;
string message = 2;
int64 payout_id = 1;
google.protobuf.StringValue notes = 2; // Optional admin notes
}
// RejectWithdrawal Command
message RejectWithdrawalRequest
{
int64 withdrawal_id = 1;
string reject_reason = 2;
}
message RejectWithdrawalResponse
{
bool success = 1;
string message = 2;
int64 payout_id = 1;
string reason = 2; // Required reason for rejection
}
// ============ Queries ============
@@ -213,43 +216,12 @@ message UserWeeklyBalanceModel
google.protobuf.Timestamp created = 10;
}
// GetWithdrawalRequests Query
message GetWithdrawalRequestsRequest
{
int32 page_index = 1;
int32 page_size = 2;
google.protobuf.Int32Value status = 3; // 0=Pending, 1=Approved, 2=Rejected, 3=Processed
google.protobuf.Int64Value user_id = 4;
}
message GetWithdrawalRequestsResponse
{
messages.MetaData meta_data = 1;
repeated WithdrawalRequestModel models = 2;
}
message WithdrawalRequestModel
{
int64 id = 1;
int64 user_id = 2;
string user_name = 3;
string phone_number = 4;
int64 amount = 5;
int32 status = 6; // 0=Pending, 1=Approved, 2=Rejected, 3=Processed
string method = 7; // Bank, Crypto, Cash
string bank_account = 8;
string bank_name = 9;
google.protobuf.Timestamp requested_at = 10;
google.protobuf.Timestamp processed_at = 11;
string admin_note = 12;
}
// GetAllWeeklyPools Query
message GetAllWeeklyPoolsRequest
{
google.protobuf.StringValue from_week = 1;
google.protobuf.StringValue to_week = 2;
google.protobuf.BoolValue only_calculated = 3;
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;
}
@@ -271,3 +243,107 @@ message WeeklyCommissionPoolModel
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;
}
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;
}
// ============ 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
}
@@ -2,7 +2,7 @@ syntax = "proto3";
package messages;
option csharp_namespace = "BackOffice.BFF.Protobuf.Common";
option csharp_namespace = "CMSMicroservice.Protobuf.Protos";
service PublicMessageContract{}
message PaginationState
{
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackageId>BackOffice.BFF.Health.Protobuf</PackageId>
<Version>1.0.0</Version>
<Authors>FourSat</Authors>
<Company>FourSat</Company>
<Product>BackOffice.BFF.Health.Protobuf</Product>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.23.3" />
<PackageReference Include="Grpc.Core.Api" Version="2.54.0" />
<PackageReference Include="Grpc.Tools" Version="2.72.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\health.proto" GrpcServices="Both" />
</ItemGroup>
</Project>
@@ -0,0 +1,33 @@
syntax = "proto3";
package health;
import "google/protobuf/timestamp.proto";
option csharp_namespace = "BackOffice.BFF.Health.Protobuf";
service HealthContract
{
rpc GetSystemHealth(GetSystemHealthRequest) returns (GetSystemHealthResponse);
}
message GetSystemHealthRequest
{
// Empty - returns all services health status
}
message GetSystemHealthResponse
{
bool overall_healthy = 1;
repeated ServiceHealthModel services = 2;
google.protobuf.Timestamp checked_at = 3;
}
message ServiceHealthModel
{
string service_name = 1;
string status = 2; // "Healthy", "Degraded", "Unhealthy"
string description = 3;
int64 response_time_ms = 4;
google.protobuf.Timestamp last_check = 5;
}
@@ -17,6 +17,7 @@ service NetworkMembershipContract
rpc GetUserNetwork(GetUserNetworkRequest) returns (GetUserNetworkResponse);
rpc GetNetworkTree(GetNetworkTreeRequest) returns (GetNetworkTreeResponse);
rpc GetNetworkMembershipHistory(GetNetworkMembershipHistoryRequest) returns (GetNetworkMembershipHistoryResponse);
rpc GetNetworkStatistics(GetNetworkStatisticsRequest) returns (GetNetworkStatisticsResponse);
}
// JoinNetwork Command
@@ -122,3 +123,47 @@ message NetworkMembershipHistoryModel
string reason = 11;
google.protobuf.Timestamp created = 12;
}
// GetNetworkStatistics Query
message GetNetworkStatisticsRequest
{
// Empty - returns overall 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;
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;
}