Compare commits
No commits in common. "2bfff006ed2b3fbf80cdc750111c90869b1badc2" and "12f61e373f5df76fee263d5e206bc097f71a2cc6" have entirely different histories.
2bfff006ed
...
12f61e373f
@ -47,7 +47,7 @@ func GenerateCertificate(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
genConfig := &models.CertificateTemplateOptions{
|
||||
Runners: addUpRunnerDonations(certificateRequest.Runners),
|
||||
Runners: certificateRequest.Runners,
|
||||
EventName: "Event name",
|
||||
Footer: "Footer",
|
||||
CurrencySymbol: "€",
|
||||
@ -71,13 +71,3 @@ func GenerateCertificate(c *fiber.Ctx) error {
|
||||
c.Set(fiber.HeaderContentType, "application/pdf")
|
||||
return c.Send(pdf)
|
||||
}
|
||||
|
||||
func addUpRunnerDonations(runners []models.RunnerWithDonations) []models.RunnerWithDonations {
|
||||
for i := 0; i < len(runners); i++ {
|
||||
for j := 0; j < len(runners[i].DistanceDonations); j++ {
|
||||
runners[i].TotalDonations += runners[i].DistanceDonations[j].Amount
|
||||
runners[i].TotalPerDistance += runners[i].DistanceDonations[j].AmountPerDistance
|
||||
}
|
||||
}
|
||||
return runners
|
||||
}
|
||||
|
@ -4,10 +4,8 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"image/png"
|
||||
"strings"
|
||||
|
||||
"git.odit.services/lfk/document-server/templates"
|
||||
"github.com/boombuler/barcode"
|
||||
@ -91,24 +89,10 @@ func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
||||
}
|
||||
|
||||
func FormatUnit(unit string, amount int) (string, error) {
|
||||
var formatted string
|
||||
switch unit {
|
||||
case "kilometer":
|
||||
formatted = fmt.Sprintf("%.3f", float64(amount)/1000)
|
||||
case "euro":
|
||||
formatted = fmt.Sprintf("%.2f", float64(amount)/100)
|
||||
default:
|
||||
return "", errors.New("unknown unit")
|
||||
}
|
||||
return strings.Replace(formatted, ".", ",", -1), nil
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||
return template.New("template").Funcs(template.FuncMap{
|
||||
"barcode": t.GenerateBarcode,
|
||||
"sponsorLogo": t.SelectSponsorImage,
|
||||
"formatUnit": FormatUnit,
|
||||
}).Parse(templateString)
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
Loading…
x
Reference in New Issue
Block a user