Files
telecom-platform/apps/carrier-connector/internal/handlers/selection_handler_methods.go
T
nutcas3 ae8b7bdce1 feat: Refactor profile handlers into modular core components with simplified operations
- Split profile_handlers.go into profile_handlers_core.go, profile_handlers_management_core.go, and profile_handlers_management_delete.go
- Simplify OrderProfileHandlerWithRepo with ICCID/IMSI-only validation and "downloaded" state
- Remove webhook and message queue notifications from order handler
- Add UpdateProfileHandler with state validation for downloaded/activated/deactivated/expired
- Add DeleteProfileHandler with existence
2026-05-01 23:26:41 +03:00

75 lines
1.9 KiB
Go

package handlers
import (
"encoding/json"
"net/http"
"time"
)
// GetSelectionHistory handles the selection history endpoint
func (h *SelectionHandler) GetSelectionHistory(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
h.writeErrorResponse(w, http.StatusMethodNotAllowed, "Method not allowed")
return
}
// Extract carrier ID from URL path
carrierID := h.extractCarrierIDFromPath(r.URL.Path, "/api/v1/selection/history/")
if carrierID == "" {
h.writeErrorResponse(w, http.StatusBadRequest, "Carrier ID is required")
return
}
history := h.manager.GetSelectionHistory(carrierID)
// Generate analytics
analytics := map[string]any{
"total_selections": len(history),
"generated_at": time.Now().Format(time.RFC3339),
}
response := SelectionHistoryResponse{
Success: true,
History: history,
Count: len(history),
Analytics: analytics,
}
h.writeJSONResponse(w, http.StatusOK, response)
}
// UpdateLearning handles the learning update endpoint
func (h *SelectionHandler) UpdateLearning(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
h.writeErrorResponse(w, http.StatusMethodNotAllowed, "Method not allowed")
return
}
var req UpdateLearningRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
h.writeErrorResponse(w, http.StatusBadRequest, "Invalid request body")
return
}
// Validate request
if req.CarrierID == "" {
h.writeErrorResponse(w, http.StatusBadRequest, "Carrier ID is required")
return
}
if req.ActualPerformance < 0 || req.ActualPerformance > 100 {
h.writeErrorResponse(w, http.StatusBadRequest, "Actual performance must be between 0 and 100")
return
}
// Update learning
h.manager.UpdateLearning(req.CarrierID, req.ActualPerformance)
response := UpdateLearningResponse{
Success: true,
Message: "Learning updated successfully",
}
h.writeJSONResponse(w, http.StatusOK, response)
}