From b76a9a33cee6bd3475af8a079ac072cb6635fe49 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sun, 3 May 2026 11:52:33 +0300 Subject: [PATCH] feat: Refactor rate plan currency integrator to simplify subscription creation and remove unused helper - Simplify SubscribeToPlanWithCurrency by creating SubscribeRequest directly instead of intermediate RatePlanSubscription struct - Remove redundant Status, StartedAt, CreatedAt, and UpdatedAt field assignments - Mark unused context parameters with underscore in calculateOverageCost and generateReason - Remove unused getHighestPriorityCarrier helper function from selection_algorithm.go --- .../internal/services/rateplan_core.go | 18 ++++-------------- .../internal/smdp/selection_algorithm.go | 16 ---------------- .../internal/smdp/selection_scoring.go | 2 +- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/apps/carrier-connector/internal/services/rateplan_core.go b/apps/carrier-connector/internal/services/rateplan_core.go index f3269a9..4c4f8ae 100644 --- a/apps/carrier-connector/internal/services/rateplan_core.go +++ b/apps/carrier-connector/internal/services/rateplan_core.go @@ -62,12 +62,11 @@ func (rpci *RatePlanCurrencyIntegrator) SubscribeToPlanWithCurrency(ctx context. exchangeRate = conversion.ExchangeRate } - // Create subscription with currency information - subscription := &rateplan.RatePlanSubscription{ + // Create subscription request with currency information + subscribeReq := &rateplan.SubscribeRequest{ ProfileID: profileID, RatePlanID: planID, - Status: rateplan.SubscriptionStatusActive, - StartedAt: time.Now(), + AutoRenew: true, Metadata: map[string]any{ "original_currency": plan.Currency, "subscription_currency": targetCurrency, @@ -75,15 +74,6 @@ func (rpci *RatePlanCurrencyIntegrator) SubscribeToPlanWithCurrency(ctx context. "subscription_price": subscriptionPrice, "exchange_rate": exchangeRate, }, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - } - - subscribeReq := &rateplan.SubscribeRequest{ - ProfileID: profileID, - RatePlanID: planID, - AutoRenew: true, - Metadata: subscription.Metadata, } createdSubscription, err := rpci.ratePlanService.SubscribeToPlan(ctx, subscribeReq) @@ -175,7 +165,7 @@ func (rpci *RatePlanCurrencyIntegrator) CalculatePlanCostInCurrency(ctx context. } // calculateOverageCost calculates overage costs for usage -func (rpci *RatePlanCurrencyIntegrator) calculateOverageCost(ctx context.Context, plan *rateplan.RatePlan, usage *rateplan.RatePlanUsage) (float64, error) { +func (rpci *RatePlanCurrencyIntegrator) calculateOverageCost(_ context.Context, plan *rateplan.RatePlan, usage *rateplan.RatePlanUsage) (float64, error) { overageCost := 0.0 // Calculate data overage diff --git a/apps/carrier-connector/internal/smdp/selection_algorithm.go b/apps/carrier-connector/internal/smdp/selection_algorithm.go index 59cfd1c..2d6aa58 100644 --- a/apps/carrier-connector/internal/smdp/selection_algorithm.go +++ b/apps/carrier-connector/internal/smdp/selection_algorithm.go @@ -181,19 +181,3 @@ func (sa *SelectionAlgorithm) PredictPerformance(carrierID string, criteria *Sel func (sa *SelectionAlgorithm) GetCarrierPerformance(carrierID string) *PerformanceMetrics { return sa.mlModel.GetCarrierPerformance(carrierID) } - -// getHighestPriorityCarrier returns the carrier with the highest priority -func (sa *SelectionAlgorithm) getHighestPriorityCarrier(carriers []*Carrier) *Carrier { - if len(carriers) == 0 { - return nil - } - - highestPriority := carriers[0] - for _, carrier := range carriers { - if carrier.Priority > highestPriority.Priority { - highestPriority = carrier - } - } - - return highestPriority -} diff --git a/apps/carrier-connector/internal/smdp/selection_scoring.go b/apps/carrier-connector/internal/smdp/selection_scoring.go index 25064ec..b6ed18b 100644 --- a/apps/carrier-connector/internal/smdp/selection_scoring.go +++ b/apps/carrier-connector/internal/smdp/selection_scoring.go @@ -184,7 +184,7 @@ func (sa *SelectionAlgorithm) calculateCapabilityScore(carrier *Carrier, profile } // generateReason creates a human-readable selection reason -func (sa *SelectionAlgorithm) generateReason(score *CarrierScore, criteria *SelectionCriteria) string { +func (sa *SelectionAlgorithm) generateReason(score *CarrierScore, _ *SelectionCriteria) string { reasons := []string{} if score.PerformanceScore > 80 {