Update vcard_qr.go

This commit is contained in:
Lizandro Guarnizo
2025-04-19 10:11:05 -05:00
parent d3b2d0ad21
commit 0de5960974
+21 -11
View File
@@ -8,6 +8,7 @@ import (
"image/png"
"log"
"os"
"strings"
"github.com/chai2010/webp"
"github.com/gofiber/fiber/v2"
@@ -107,18 +108,27 @@ func CreateQr(c *fiber.Ctx) error {
"error": "Error al consultar la base de datos",
})
}
} else {
// Ya existe, actualizar
existing.Qr = url
existing.UsuarioID = data.FirstName
existing.Email = data.Email
if err := models.UpdateQrVcard(&existing); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error al actualizar el QR en la base de datos",
})
} else {
// Ya existe, eliminar el QR anterior en OSS
oldFilePath := strings.Replace(existing.Qr, fmt.Sprintf("https://%s.%s/", ossService.BucketName, ossService.Endpoint), "", 1)
if err := ossService.DeleteFile(oldFilePath); err != nil {
log.Printf("Error al eliminar QR anterior en OSS: %v", err)
// No retornamos error, porque queremos continuar de todas formas
}
// Actualizar el registro
existing.Qr = url
existing.UsuarioID = data.FirstName
existing.Email = data.Email
if err := models.UpdateQrVcard(&existing); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error al actualizar el QR en la base de datos",
})
}
}
}
// 8. Retornar la URL
return c.JSON(fiber.Map{