mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-10 14:05:14 +00:00
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
This commit is contained in:
@@ -62,12 +62,11 @@ func (rpci *RatePlanCurrencyIntegrator) SubscribeToPlanWithCurrency(ctx context.
|
|||||||
exchangeRate = conversion.ExchangeRate
|
exchangeRate = conversion.ExchangeRate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create subscription with currency information
|
// Create subscription request with currency information
|
||||||
subscription := &rateplan.RatePlanSubscription{
|
subscribeReq := &rateplan.SubscribeRequest{
|
||||||
ProfileID: profileID,
|
ProfileID: profileID,
|
||||||
RatePlanID: planID,
|
RatePlanID: planID,
|
||||||
Status: rateplan.SubscriptionStatusActive,
|
AutoRenew: true,
|
||||||
StartedAt: time.Now(),
|
|
||||||
Metadata: map[string]any{
|
Metadata: map[string]any{
|
||||||
"original_currency": plan.Currency,
|
"original_currency": plan.Currency,
|
||||||
"subscription_currency": targetCurrency,
|
"subscription_currency": targetCurrency,
|
||||||
@@ -75,15 +74,6 @@ func (rpci *RatePlanCurrencyIntegrator) SubscribeToPlanWithCurrency(ctx context.
|
|||||||
"subscription_price": subscriptionPrice,
|
"subscription_price": subscriptionPrice,
|
||||||
"exchange_rate": exchangeRate,
|
"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)
|
createdSubscription, err := rpci.ratePlanService.SubscribeToPlan(ctx, subscribeReq)
|
||||||
@@ -175,7 +165,7 @@ func (rpci *RatePlanCurrencyIntegrator) CalculatePlanCostInCurrency(ctx context.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculateOverageCost calculates overage costs for usage
|
// 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
|
overageCost := 0.0
|
||||||
|
|
||||||
// Calculate data overage
|
// Calculate data overage
|
||||||
|
|||||||
@@ -181,19 +181,3 @@ func (sa *SelectionAlgorithm) PredictPerformance(carrierID string, criteria *Sel
|
|||||||
func (sa *SelectionAlgorithm) GetCarrierPerformance(carrierID string) *PerformanceMetrics {
|
func (sa *SelectionAlgorithm) GetCarrierPerformance(carrierID string) *PerformanceMetrics {
|
||||||
return sa.mlModel.GetCarrierPerformance(carrierID)
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ func (sa *SelectionAlgorithm) calculateCapabilityScore(carrier *Carrier, profile
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generateReason creates a human-readable selection reason
|
// 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{}
|
reasons := []string{}
|
||||||
|
|
||||||
if score.PerformanceScore > 80 {
|
if score.PerformanceScore > 80 {
|
||||||
|
|||||||
Reference in New Issue
Block a user