feat: sesión 1 año + validación sintaxis plantilla en tiempo real
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"html/template"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
||||
@@ -101,6 +102,24 @@ func PreviewPlantilla(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{"html": html, "ok": true})
|
||||
}
|
||||
|
||||
// ValidarPlantilla comprueba si el CuerpoHTML es un Go template válido
|
||||
func ValidarPlantilla(c *fiber.Ctx) error {
|
||||
var body struct {
|
||||
HTML string `json:"html"`
|
||||
}
|
||||
if err := c.BodyParser(&body); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
html := strings.TrimSpace(body.HTML)
|
||||
if html == "" {
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
if _, err := template.New("validate").Parse(html); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"ok": false, "error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
func TestEnvioPlantilla(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 32)
|
||||
if err != nil {
|
||||
|
||||
@@ -42,6 +42,7 @@ func RenovacionesRoutes(protected fiber.Router) {
|
||||
protected.Delete("/api/plantillas-correo/:id", controllers.DeletePlantilla)
|
||||
protected.Get("/api/plantillas-correo/:id/preview", controllers.PreviewPlantilla)
|
||||
protected.Post("/api/plantillas-correo/:id/test", controllers.TestEnvioPlantilla)
|
||||
protected.Post("/api/plantillas-correo/validate", controllers.ValidarPlantilla)
|
||||
|
||||
// ─── Reglas de notificación ───────────────────────────────────────
|
||||
protected.Get("/reglas-notificacion", middlewares.MenuMiddleware, controllers.ReglasView)
|
||||
|
||||
Reference in New Issue
Block a user