feat: Config from env
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
// @Param data body models.CardRequest true "Card data"
|
||||
// @Produce application/pdf
|
||||
// @Router /cards [post]
|
||||
func GenerateCard(c *fiber.Ctx) error {
|
||||
func (h *DefaultHandler) GenerateCard(c *fiber.Ctx) error {
|
||||
cardRequest := new(models.CardRequest)
|
||||
if err := c.BodyParser(cardRequest); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
@@ -47,10 +47,10 @@ func GenerateCard(c *fiber.Ctx) error {
|
||||
|
||||
genConfig := &models.CardTemplateOptions{
|
||||
CardSegments: splitCardSegments(cardRequest.Cards),
|
||||
EventName: "Event name",
|
||||
CardSubtitle: "Card subtitle",
|
||||
BarcodeFormat: "ean13",
|
||||
BarcodePrefix: "",
|
||||
EventName: h.Config.EventName,
|
||||
CardSubtitle: h.Config.CardSubtitle,
|
||||
BarcodeFormat: h.Config.CardBarcodeFormat,
|
||||
BarcodePrefix: h.Config.CardBarcodePrefix,
|
||||
}
|
||||
|
||||
result, err := generator.Execute(template, genConfig)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
// @Param data body models.CertificateRequest true "Certificate data"
|
||||
// @Produce application/pdf
|
||||
// @Router /certificates [post]
|
||||
func GenerateCertificate(c *fiber.Ctx) error {
|
||||
func (h *DefaultHandler) GenerateCertificate(c *fiber.Ctx) error {
|
||||
certificateRequest := new(models.CertificateRequest)
|
||||
if err := c.BodyParser(certificateRequest); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
@@ -47,9 +47,9 @@ func GenerateCertificate(c *fiber.Ctx) error {
|
||||
|
||||
genConfig := &models.CertificateTemplateOptions{
|
||||
Runners: addUpRunnerDonations(certificateRequest.Runners),
|
||||
EventName: "Event name",
|
||||
Footer: "Footer",
|
||||
CurrencySymbol: "€",
|
||||
EventName: h.Config.EventName,
|
||||
Footer: h.Config.CertificateFooter,
|
||||
CurrencySymbol: h.Config.CurrencySymbol,
|
||||
Locale: certificateRequest.Locale,
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
// @Param data body models.ContractRequest true "Contract data"
|
||||
// @Produce application/pdf
|
||||
// @Router /contracts [post]
|
||||
func GenerateContract(c *fiber.Ctx) error {
|
||||
func (h *DefaultHandler) GenerateContract(c *fiber.Ctx) error {
|
||||
contract := new(models.ContractRequest)
|
||||
if err := c.BodyParser(contract); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
@@ -49,12 +49,12 @@ func GenerateContract(c *fiber.Ctx) error {
|
||||
|
||||
genConfig := &models.ContractTemplateOptions{
|
||||
Runners: contract.Runners,
|
||||
CurrencySymbol: "€",
|
||||
Disclaimer: "This is a disclaimer",
|
||||
ReceiptMinimumAmount: 10,
|
||||
EventName: "Event name",
|
||||
BarcodeFormat: "ean13",
|
||||
BarcodePrefix: "1",
|
||||
CurrencySymbol: h.Config.CurrencySymbol,
|
||||
Disclaimer: h.Config.SponosringDisclaimer,
|
||||
ReceiptMinimumAmount: h.Config.SponsoringReceiptMinimum,
|
||||
EventName: h.Config.EventName,
|
||||
BarcodeFormat: h.Config.SponsoringBarcodeFormat,
|
||||
BarcodePrefix: h.Config.SponsoringBarcodePrefix,
|
||||
}
|
||||
|
||||
result, err := generator.Execute(template, genConfig)
|
||||
|
||||
16
handlers/handlers.go
Normal file
16
handlers/handlers.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"git.odit.services/lfk/document-server/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type Handler interface {
|
||||
GenerateCard(*fiber.Ctx) error
|
||||
GenerateContract(*fiber.Ctx) error
|
||||
GenerateCertificate(*fiber.Ctx) error
|
||||
}
|
||||
|
||||
type DefaultHandler struct {
|
||||
Config *models.Config
|
||||
}
|
||||
@@ -2,6 +2,6 @@ package handlers
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func NotFoundHandler(c *fiber.Ctx) error {
|
||||
func (h *DefaultHandler) NotFoundHandler(c *fiber.Ctx) error {
|
||||
return c.Status(404).SendString("Not Found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user