This commit is contained in:
Lizandro Guarnizo
2026-06-04 22:49:16 -05:00
parent 72744a1325
commit 7329bac898
8 changed files with 176 additions and 18 deletions
+9
View File
@@ -155,6 +155,15 @@ func UpdateAiConfigHandler(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"ok": true})
}
// GetAiConfigSelect devuelve lista simple para selects
func GetAiConfigSelect(c *fiber.Ctx) error {
items, err := models.GetAiConfigSelect()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
}
return c.JSON(fiber.Map{"registros": items})
}
// DeleteAiConfigHandler elimina una configuración de IA.
func DeleteAiConfigHandler(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
+20 -8
View File
@@ -62,13 +62,16 @@ func GetContratos(c *fiber.Ctx) error {
func CreateContrato(c *fiber.Ctx) error {
type Input struct {
ClienteID uint `json:"cliente_id"`
ServicioIDs []uint `json:"servicio_ids"`
FechaInicio string `json:"fecha_inicio"`
FechaVencimiento string `json:"fecha_vencimiento"`
ClienteID uint `json:"cliente_id"`
ServicioIDs []uint `json:"servicio_ids"`
FechaInicio string `json:"fecha_inicio"`
FechaVencimiento string `json:"fecha_vencimiento"`
PrecioAcordado float64 `json:"precio_acordado"`
AutoRenovar bool `json:"auto_renovar"`
Notas string `json:"notas"`
AutoRenovar bool `json:"auto_renovar"`
Notas string `json:"notas"`
ServidorID *uint `json:"servidor_id"`
ConxDbID *uint `json:"conx_db_id"`
AiConfigID *uint `json:"ai_config_id"`
}
var inp Input
if err := c.BodyParser(&inp); err != nil {
@@ -86,10 +89,13 @@ func CreateContrato(c *fiber.Ctx) error {
ClienteID: inp.ClienteID,
FechaInicio: fi,
FechaVencimiento: fv,
PrecioAcordado: inp.PrecioAcordado,
PrecioAcordado: float64(inp.PrecioAcordado),
AutoRenovar: inp.AutoRenovar,
Notas: inp.Notas,
Estado: "activo",
ServidorID: inp.ServidorID,
ConxDbID: inp.ConxDbID,
AiConfigID: inp.AiConfigID,
}
if err := models.CreateContrato(m, inp.ServicioIDs); err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
@@ -115,10 +121,13 @@ func UpdateContrato(c *fiber.Ctx) error {
PrecioAcordado float64 `json:"precio_acordado"`
AutoRenovar bool `json:"auto_renovar"`
Notas string `json:"notas"`
ServidorID *uint `json:"servidor_id"`
ConxDbID *uint `json:"conx_db_id"`
AiConfigID *uint `json:"ai_config_id"`
}
var inp Input
if err := c.BodyParser(&inp); err != nil {
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
return c.Status(400).JSON(fiber.Map{"error": "ID inválido"})
}
existing, err := models.GetContratoByID(uint(id))
if err != nil {
@@ -136,6 +145,9 @@ func UpdateContrato(c *fiber.Ctx) error {
existing.PrecioAcordado = inp.PrecioAcordado
existing.AutoRenovar = inp.AutoRenovar
existing.Notas = inp.Notas
existing.ServidorID = inp.ServidorID
existing.ConxDbID = inp.ConxDbID
existing.AiConfigID = inp.AiConfigID
if err := models.UpdateContrato(*existing, inp.ServicioIDs); err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
}
+9
View File
@@ -125,3 +125,12 @@ func DeleteConxDb(c *fiber.Ctx) error {
"message": "conx ssh eliminado exitosamente",
})
}
func GetConxDbSelect(c *fiber.Ctx) error {
servidorID := c.Query("servidor_id")
items, err := models.GetConxDbSelect(servidorID)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
}
return c.JSON(fiber.Map{"registros": items})
}
+2
View File
@@ -65,6 +65,7 @@ func UserRoutes(app fiber.Router) {
// Rutas de conexiones db
protected.Get("/conexion_db", middlewares.MenuMiddleware, controllers.ConxDb) // Renderizar la vista
protected.Get("/loadconexiondb", controllers.GetConxDb) // Obtener
protected.Get("/api/conxdb/select", controllers.GetConxDbSelect) // Select (filtrado por ?servidor_id=)
protected.Post("/conexiondb", controllers.CreateConxDb) // Crear
protected.Put("/conexiondb/:id", controllers.UpdateConxDb) // Actualizar
protected.Delete("/conexiondb/:id", controllers.DeleteConxDb) // Eliminar
@@ -284,6 +285,7 @@ func UserRoutes(app fiber.Router) {
// ─── Configuraciones de IA (Qwen, OpenAI, etc.) ─────────────────────────
protected.Get("/ai-config", middlewares.MenuMiddleware, controllers.AiConfigIndex)
protected.Get("/ai-config/list", controllers.GetAiConfigs)
protected.Get("/api/ai-config/select", controllers.GetAiConfigSelect)
protected.Post("/ai-config", controllers.CreateAiConfigHandler)
protected.Put("/ai-config/:id", controllers.UpdateAiConfigHandler)
protected.Delete("/ai-config/:id", controllers.DeleteAiConfigHandler)