Compare commits
No commits in common. "79a0062f60f1ab162dfd98a02a5dd9178f074cce" and "2537235ce6d9a2a120bea9f4550b3e4eea21c138" have entirely different histories.
79a0062f60
...
2537235ce6
@ -1,73 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"slices"
|
||||
|
||||
"git.odit.services/lfk/document-server/models"
|
||||
"git.odit.services/lfk/document-server/services"
|
||||
"git.odit.services/lfk/document-server/templates"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// GenerateCertificate godoc
|
||||
// @Summary Generate runner certificates
|
||||
// @Description Generate certificates based on the provided data
|
||||
// @Tags certificates
|
||||
// @Accept json
|
||||
// @Param data body models.CertificateRequest true "Certificate data"
|
||||
// @Produce application/pdf
|
||||
// @Router /certificates [post]
|
||||
func GenerateCertificate(c *fiber.Ctx) error {
|
||||
certificateRequest := new(models.CertificateRequest)
|
||||
if err := c.BodyParser(certificateRequest); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
if !slices.Contains([]string{"en", "de"}, certificateRequest.Locale) {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "Invalid locale",
|
||||
})
|
||||
}
|
||||
|
||||
generator := services.DefaultTemplater{}
|
||||
templateString, err := templates.GetTemplate(certificateRequest.Locale, "certificate")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "Template not found",
|
||||
})
|
||||
}
|
||||
template, err := generator.StringToTemplate(templateString)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
genConfig := &models.CertificateTemplateOptions{
|
||||
Runners: certificateRequest.Runners,
|
||||
EventName: "Event name",
|
||||
Footer: "Footer",
|
||||
CurrencySymbol: "€",
|
||||
}
|
||||
|
||||
result, err := generator.Execute(template, genConfig)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
c.Set(fiber.HeaderContentType, "text/html")
|
||||
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(),
|
||||
})
|
||||
}
|
||||
|
||||
c.Set(fiber.HeaderContentType, "application/pdf")
|
||||
return c.Send(pdf)
|
||||
}
|
1
main.go
1
main.go
@ -36,7 +36,6 @@ func main() {
|
||||
})
|
||||
v1.Post("/contracts", handlers.GenerateContract)
|
||||
v1.Post("/cards", handlers.GenerateCard)
|
||||
v1.Post("/certificates", handlers.GenerateCertificate)
|
||||
|
||||
app.Use(handlers.NotFoundHandler)
|
||||
docs.SwaggerInfo.BasePath = "/"
|
||||
|
@ -1,40 +0,0 @@
|
||||
package models
|
||||
|
||||
type CertificateRequest struct {
|
||||
Runners []RunnerWithDonations `json:"runners"`
|
||||
Locale string `json:"locale" enums:"en,de"`
|
||||
}
|
||||
|
||||
type RunnerWithDonations struct {
|
||||
ID int `json:"id"`
|
||||
FirstName string `json:"first_name"`
|
||||
MiddleName string `json:"middle_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Group Group `json:"group"`
|
||||
Distance int `json:"distance"`
|
||||
DistanceDonations []DistanceDonation `json:"distance_donations"`
|
||||
TotalPerDistance int `json:"total_per_distance"`
|
||||
TotalDonations int `json:"total_donations"`
|
||||
}
|
||||
|
||||
type DistanceDonation struct {
|
||||
ID int `json:"id"`
|
||||
Amount int `json:"amount"`
|
||||
PaidAmount int `json:"paid_amount"`
|
||||
AmountPerDistance int `json:"amount_per_distance"`
|
||||
Donor Donor `json:"donor"`
|
||||
}
|
||||
|
||||
type Donor struct {
|
||||
ID int `json:"id"`
|
||||
FirstName string `json:"first_name"`
|
||||
MiddleName string `json:"middle_name"`
|
||||
LastName string `json:"last_name"`
|
||||
}
|
||||
|
||||
type CertificateTemplateOptions struct {
|
||||
Runners []RunnerWithDonations `json:"runners"`
|
||||
EventName string `json:"event_name"`
|
||||
Footer string `json:"footer"`
|
||||
CurrencySymbol string `json:"currency_symbol"`
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user