mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-08 13:05:14 +00:00
refactor: Extract helper methods, fix formatting, and add TODO comments for pending implementations
- Extract generateHistoryAnalytics helper in selection_handler_methods.go - Extract generateRecommendations helper in selection_handler_selection.go - Extract parsePositiveInt helper in rateplan_handlers_analytics.go - Replace hardcoded URL path with action parameter in ES2Service.sendActivationRequest - Add TODO comments for wrapCurrencyService and updateCarrierWeights pending implementations - Fix struct field alignment and formatting in carrier_methods.go
This commit is contained in:
@@ -16,7 +16,7 @@ func (e *ES2Service) sendActivationRequest(ctx context.Context, req ActivationRe
|
|||||||
return fmt.Errorf("failed to marshal activation request: %w", err)
|
return fmt.Errorf("failed to marshal activation request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/es2/activate", e.config.BaseURL)
|
url := fmt.Sprintf("%s/es2/%s", e.config.BaseURL, action)
|
||||||
httpReq, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(jsonData))
|
httpReq, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create HTTP request: %w", err)
|
return fmt.Errorf("failed to create HTTP request: %w", err)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -111,12 +110,7 @@ func (h *RatePlanHandler) GetRevenueAnalytics(c *gin.Context) {
|
|||||||
|
|
||||||
// GetPopularPlans handles retrieving the most popular rate plans
|
// GetPopularPlans handles retrieving the most popular rate plans
|
||||||
func (h *RatePlanHandler) GetPopularPlans(c *gin.Context) {
|
func (h *RatePlanHandler) GetPopularPlans(c *gin.Context) {
|
||||||
limit := 10 // default limit
|
limit := parsePositiveInt(c.Query("limit"), 10)
|
||||||
if limitStr := c.Query("limit"); limitStr != "" {
|
|
||||||
if parsedLimit, err := strconv.Atoi(limitStr); err == nil && parsedLimit > 0 {
|
|
||||||
limit = parsedLimit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plans, err := h.service.GetPopularPlans(c.Request.Context(), limit)
|
plans, err := h.service.GetPopularPlans(c.Request.Context(), limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetSelectionHistory handles the selection history endpoint
|
// GetSelectionHistory handles the selection history endpoint
|
||||||
@@ -24,10 +23,7 @@ func (h *SelectionHandler) GetSelectionHistory(w http.ResponseWriter, r *http.Re
|
|||||||
history := h.manager.GetSelectionHistory(carrierID)
|
history := h.manager.GetSelectionHistory(carrierID)
|
||||||
|
|
||||||
// Generate analytics
|
// Generate analytics
|
||||||
analytics := map[string]any{
|
analytics := h.generateHistoryAnalytics(history)
|
||||||
"total_selections": len(history),
|
|
||||||
"generated_at": time.Now().Format(time.RFC3339),
|
|
||||||
}
|
|
||||||
|
|
||||||
response := SelectionHistoryResponse{
|
response := SelectionHistoryResponse{
|
||||||
Success: true,
|
Success: true,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (h *SelectionHandler) SelectOptimalCarrier(w http.ResponseWriter, r *http.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate recommendations
|
// Generate recommendations
|
||||||
recommendations := []string{"Carrier selected successfully"}
|
recommendations := h.generateRecommendations(score, criteria)
|
||||||
|
|
||||||
response := SelectOptimalCarrierResponse{
|
response := SelectOptimalCarrierResponse{
|
||||||
Success: true,
|
Success: true,
|
||||||
@@ -69,7 +69,7 @@ func (h *SelectionHandler) SelectOptimalCarrier(w http.ResponseWriter, r *http.R
|
|||||||
CapabilityScore: score.CapabilityScore,
|
CapabilityScore: score.CapabilityScore,
|
||||||
SelectedAt: score.SelectedAt.Format(time.RFC3339),
|
SelectedAt: score.SelectedAt.Format(time.RFC3339),
|
||||||
Reason: score.Reason,
|
Reason: score.Reason,
|
||||||
Recommendations: recommendations,
|
Recommendations: recommendations,
|
||||||
}
|
}
|
||||||
|
|
||||||
h.writeJSONResponse(w, http.StatusOK, response)
|
h.writeJSONResponse(w, http.StatusOK, response)
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ type TenantAwareServices struct {
|
|||||||
|
|
||||||
// wrapCurrencyService creates a tenant-aware currency service
|
// wrapCurrencyService creates a tenant-aware currency service
|
||||||
func (m *TenantIntegrationManager) wrapCurrencyService(tenantID string) currency.BillingService {
|
func (m *TenantIntegrationManager) wrapCurrencyService(tenantID string) currency.BillingService {
|
||||||
// This would wrap the existing currency service with tenant isolation
|
// TODO: Implement tenant isolation for currency service
|
||||||
// Implementation depends on the actual currency service structure
|
// The tenantID parameter should be used to filter currency operations by tenant
|
||||||
return m.currencyService // Placeholder - would need actual wrapping
|
// For now, return the base service - implementation needed for multi-tenant isolation
|
||||||
|
_ = tenantID // Suppress unused parameter warning until implementation is complete
|
||||||
|
return m.currencyService
|
||||||
}
|
}
|
||||||
|
|
||||||
// TenantResourceQuotaChecker checks resource quotas before operations
|
// TenantResourceQuotaChecker checks resource quotas before operations
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
|
|
||||||
func (csi *CarrierSelectionIntegrator) getAvailableRatePlans(ctx context.Context, region string, planType PlanType, maxBudget float64) ([]*RatePlan, error) {
|
func (csi *CarrierSelectionIntegrator) getAvailableRatePlans(ctx context.Context, region string, planType PlanType, maxBudget float64) ([]*RatePlan, error) {
|
||||||
filter := &RatePlanFilter{
|
filter := &RatePlanFilter{
|
||||||
Region: region,
|
Region: region,
|
||||||
PlanType: planType,
|
PlanType: planType,
|
||||||
Status: PlanStatusActive,
|
Status: PlanStatusActive,
|
||||||
IsActive: &[]bool{true}[0],
|
IsActive: &[]bool{true}[0],
|
||||||
MaxPrice: maxBudget,
|
MaxPrice: maxBudget,
|
||||||
}
|
}
|
||||||
|
|
||||||
return csi.ratePlanRepo.ListRatePlans(ctx, filter)
|
return csi.ratePlanRepo.ListRatePlans(ctx, filter)
|
||||||
@@ -113,18 +113,18 @@ func (csi *CarrierSelectionIntegrator) calculateCombinedScore(carrier *smdp.Carr
|
|||||||
|
|
||||||
func (csi *CarrierSelectionIntegrator) createRecommendation(plan *RatePlan, carrier *smdp.Carrier, criteria *RecommendationCriteria) *RatePlanRecommendation {
|
func (csi *CarrierSelectionIntegrator) createRecommendation(plan *RatePlan, carrier *smdp.Carrier, criteria *RecommendationCriteria) *RatePlanRecommendation {
|
||||||
recommendation := &RatePlanRecommendation{
|
recommendation := &RatePlanRecommendation{
|
||||||
RatePlanID: plan.ID,
|
RatePlanID: plan.ID,
|
||||||
RatePlanName: plan.Name,
|
RatePlanName: plan.Name,
|
||||||
CarrierID: carrier.ID,
|
CarrierID: carrier.ID,
|
||||||
CarrierName: carrier.Name,
|
CarrierName: carrier.Name,
|
||||||
Price: plan.BasePrice,
|
Price: plan.BasePrice,
|
||||||
Currency: plan.Currency,
|
Currency: plan.Currency,
|
||||||
Relevance: csi.calculateRelevance(plan, criteria),
|
Relevance: csi.calculateRelevance(plan, criteria),
|
||||||
Features: plan.Features,
|
Features: plan.Features,
|
||||||
DataAllowance: plan.DataAllowance,
|
DataAllowance: plan.DataAllowance,
|
||||||
VoiceAllowance: plan.VoiceAllowance,
|
VoiceAllowance: plan.VoiceAllowance,
|
||||||
SMSAllowance: plan.SMSAllowance,
|
SMSAllowance: plan.SMSAllowance,
|
||||||
RecommendedAt: time.Now(),
|
RecommendedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return recommendation
|
return recommendation
|
||||||
@@ -159,8 +159,10 @@ func (csi *CarrierSelectionIntegrator) calculateRelevance(plan *RatePlan, criter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (csi *CarrierSelectionIntegrator) updateCarrierWeights(analytics *UsageAnalytics) {
|
func (csi *CarrierSelectionIntegrator) updateCarrierWeights(analytics *UsageAnalytics) {
|
||||||
// This would update the carrier selection weights based on usage patterns
|
// TODO: Implement actual weight update based on analytics
|
||||||
// Implementation depends on the specific carrier selection algorithm
|
// The analytics parameter should be used to adjust carrier selection weights
|
||||||
|
// For now, just log that we received the analytics data
|
||||||
|
_ = analytics // Suppress unused parameter warning until implementation is complete
|
||||||
csi.logger.Info("Updated carrier selection weights based on usage analytics")
|
csi.logger.Info("Updated carrier selection weights based on usage analytics")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,16 +189,16 @@ func (csi *CarrierSelectionIntegrator) getPlanAnalytics(ctx context.Context, pla
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &RatePlanAnalytics{
|
return &RatePlanAnalytics{
|
||||||
RatePlanID: plan.ID,
|
RatePlanID: plan.ID,
|
||||||
RatePlanName: plan.Name,
|
RatePlanName: plan.Name,
|
||||||
BasePrice: plan.BasePrice,
|
BasePrice: plan.BasePrice,
|
||||||
Currency: plan.Currency,
|
Currency: plan.Currency,
|
||||||
ActiveSubscriptions: subscriptionCount,
|
ActiveSubscriptions: subscriptionCount,
|
||||||
PlanType: plan.PlanType,
|
PlanType: plan.PlanType,
|
||||||
BillingCycle: plan.BillingCycle,
|
BillingCycle: plan.BillingCycle,
|
||||||
DataAllowance: plan.DataAllowance,
|
DataAllowance: plan.DataAllowance,
|
||||||
VoiceAllowance: plan.VoiceAllowance,
|
VoiceAllowance: plan.VoiceAllowance,
|
||||||
SMSAllowance: plan.SMSAllowance,
|
SMSAllowance: plan.SMSAllowance,
|
||||||
Features: plan.Features,
|
Features: plan.Features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user