Update vcard_qr.go
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"image/png"
|
"image/png"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/chai2010/webp"
|
"github.com/chai2010/webp"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
@@ -107,18 +108,27 @@ func CreateQr(c *fiber.Ctx) error {
|
|||||||
"error": "Error al consultar la base de datos",
|
"error": "Error al consultar la base de datos",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ya existe, actualizar
|
// Ya existe, eliminar el QR anterior en OSS
|
||||||
existing.Qr = url
|
oldFilePath := strings.Replace(existing.Qr, fmt.Sprintf("https://%s.%s/", ossService.BucketName, ossService.Endpoint), "", 1)
|
||||||
existing.UsuarioID = data.FirstName
|
|
||||||
existing.Email = data.Email
|
if err := ossService.DeleteFile(oldFilePath); err != nil {
|
||||||
|
log.Printf("Error al eliminar QR anterior en OSS: %v", err)
|
||||||
if err := models.UpdateQrVcard(&existing); err != nil {
|
// No retornamos error, porque queremos continuar de todas formas
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
}
|
||||||
"error": "Error al actualizar el QR en la base de datos",
|
|
||||||
})
|
// 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
|
// 8. Retornar la URL
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
|
|||||||
Reference in New Issue
Block a user