package controllers import ( "math" "strconv" "github.com/gofiber/fiber/v2" "github.com/sujit-baniya/fiber-boilerplate/pkg/models" "github.com/sujit-baniya/fiber-boilerplate/pkg/services" ) // GetArquitecturas lista los patrones de arquitectura de referencia. func GetArquitecturas(c *fiber.Ctx) error { page, _ := strconv.Atoi(c.Query("page", "1")) limit, _ := strconv.Atoi(c.Query("limit", "20")) if page < 1 { page = 1 } offset := (page - 1) * limit records, total, err := models.GetAllArquitecturas(limit, offset, c.Query("search"), c.Query("solo_referencias") == "true") if err != nil { return c.Status(500).JSON(fiber.Map{"error": err.Error()}) } return c.JSON(fiber.Map{ "registros": records, "total": total, "totalPages": int(math.Ceil(float64(total) / float64(limit))), "page": page, }) } type crearArquitecturaRequest struct { Requerimiento string `json:"requerimiento"` Propuesta string `json:"propuesta"` Nombre string `json:"nombre"` ClienteID uint `json:"cliente_id"` GuardarComoReferencia bool `json:"guardar_como_referencia"` } // CreateArquitectura genera el PDF de una propuesta técnica. // POST /api/v2/arquitecturas func CreateArquitectura(c *fiber.Ctx) error { var req crearArquitecturaRequest if err := c.BodyParser(&req); err != nil { return c.Status(400).JSON(fiber.Map{"error": err.Error()}) } var clienteID *uint if req.ClienteID != 0 { clienteID = &req.ClienteID } doc, err := services.GenerarArquitectura(req.Requerimiento, req.Propuesta, req.Nombre, clienteID, req.GuardarComoReferencia, generadoPorFromContext(c)) if err != nil { return c.Status(400).JSON(fiber.Map{"error": err.Error()}) } return c.Status(201).JSON(fiber.Map{"ok": true, "documento": doc}) }