up
This commit is contained in:
@@ -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()})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user