fix(card): Use correct template endpoints

This commit is contained in:
2024-12-03 18:51:34 +01:00
parent 1657a10dec
commit 5dbe7816cd
3 changed files with 24 additions and 12 deletions

View File

@@ -48,6 +48,7 @@ func GenerateCard(c *fiber.Ctx) error {
genConfig := &models.CardTemplateOptions{
Cards: cardRequest.Cards,
CardsSwapped: invertCardArrayItems(cardRequest.Cards),
EventName: "Event name",
CardSubtitle: "Card subtitle",
BarcodeFormat: "ean13",
@@ -60,15 +61,24 @@ func GenerateCard(c *fiber.Ctx) error {
"error": err.Error(),
})
}
c.Set(fiber.HeaderContentType, "text/html")
return c.SendString(result)
// converter := services.GotenbergConverter{BaseUrl: "http://localhost:3001"}
// pdf, err := converter.ToPdf(result, "a4", false)
// if err != nil {
// return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
// "error": err.Error(),
// })
// }
converter := services.GotenbergConverter{BaseUrl: "http://localhost:3001"}
pdf, err := converter.ToPdf(result, "a5", true)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
c.Set(fiber.HeaderContentType, "application/pdf")
return c.Send(pdf)
// c.Set(fiber.HeaderContentType, "application/pdf")
// return c.Send(pdf)
}
func invertCardArrayItems(cards []models.Card) []models.Card {
inverted := make([]models.Card, 0)
for i := len(cards) - 1; i >= 0; i-- {
inverted = append(inverted, cards[i])
}
return inverted
}