mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-21 19:38:49 +00:00
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
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user