Files
telecom-platform/apps/carrier-connector/internal/handlers/smdp_handler_operations.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

78 lines
1.8 KiB
Go

package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
)
// RemoveCarrier handles removing a carrier
func (h *SMDPHandler) RemoveCarrier(c *gin.Context) {
carrierID := c.Param("carrier_id")
if carrierID == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Carrier ID is required"})
return
}
if err := h.manager.RemoveCarrier(carrierID); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Failed to remove carrier",
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "Carrier removed successfully",
})
}
// GetSelectionHistory handles selection history requests
func (h *SMDPHandler) GetSelectionHistory(c *gin.Context) {
carrierID := c.Param("carrier_id")
if carrierID == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Carrier ID is required"})
return
}
history := h.manager.GetSelectionHistory(carrierID)
c.JSON(http.StatusOK, gin.H{
"success": true,
"history": history,
"count": len(history),
})
}
// UpdateLearning handles learning update requests
func (h *SMDPHandler) UpdateLearning(c *gin.Context) {
carrierID := c.Param("carrier_id")
if carrierID == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Carrier ID is required"})
return
}
var req struct {
ActualPerformance float64 `json:"actual_performance"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
return
}
if req.ActualPerformance < 0 || req.ActualPerformance > 100 {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Actual performance must be between 0 and 100",
})
return
}
h.manager.UpdateLearning(carrierID, req.ActualPerformance)
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "Learning updated successfully",
})
}