Compare commits
No commits in common. "5c932158e9c89a24e05c8815ebda7acebe9dae33" and "28de60d3754a705d64019c6cfe0c0c4ee84815ef" have entirely different histories.
5c932158e9
...
28de60d375
66
docs/docs.go
66
docs/docs.go
@ -23,47 +23,8 @@ const docTemplate = `{
|
|||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {
|
"paths": {
|
||||||
"/v1/barcodes/{type}/{content}": {
|
"/cards": {
|
||||||
"get": {
|
|
||||||
"description": "Generate barcodes based on the provided data",
|
|
||||||
"produces": [
|
|
||||||
"image/png"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"barcodes"
|
|
||||||
],
|
|
||||||
"summary": "Generate barcodes",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"enum": [
|
|
||||||
"ean13",
|
|
||||||
"code128"
|
|
||||||
],
|
|
||||||
"type": "string",
|
|
||||||
"description": "Barcode type",
|
|
||||||
"name": "type",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"minLength": 1,
|
|
||||||
"type": "string",
|
|
||||||
"description": "Barcode content",
|
|
||||||
"name": "content",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/pdfs/cards": {
|
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"ApiKeyAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Generate cards based on the provided data",
|
"description": "Generate cards based on the provided data",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -72,7 +33,7 @@ const docTemplate = `{
|
|||||||
"application/pdf"
|
"application/pdf"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"pdfs"
|
"cards"
|
||||||
],
|
],
|
||||||
"summary": "Generate runner cards",
|
"summary": "Generate runner cards",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@ -89,13 +50,8 @@ const docTemplate = `{
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/v1/pdfs/certificates": {
|
"/certificates": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"ApiKeyAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Generate certificates based on the provided data",
|
"description": "Generate certificates based on the provided data",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -104,7 +60,7 @@ const docTemplate = `{
|
|||||||
"application/pdf"
|
"application/pdf"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"pdfs"
|
"certificates"
|
||||||
],
|
],
|
||||||
"summary": "Generate runner certificates",
|
"summary": "Generate runner certificates",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@ -121,13 +77,8 @@ const docTemplate = `{
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/v1/pdfs/contracts": {
|
"/contracts": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"ApiKeyAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Generate a contract based on the provided data",
|
"description": "Generate a contract based on the provided data",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -136,7 +87,7 @@ const docTemplate = `{
|
|||||||
"application/pdf"
|
"application/pdf"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"pdfs"
|
"contracts"
|
||||||
],
|
],
|
||||||
"summary": "Generate a contract",
|
"summary": "Generate a contract",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@ -384,7 +335,12 @@ const docTemplate = `{
|
|||||||
"name": "key",
|
"name": "key",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}`
|
}`
|
||||||
|
|
||||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||||
|
@ -14,47 +14,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"paths": {
|
"paths": {
|
||||||
"/v1/barcodes/{type}/{content}": {
|
"/cards": {
|
||||||
"get": {
|
|
||||||
"description": "Generate barcodes based on the provided data",
|
|
||||||
"produces": [
|
|
||||||
"image/png"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"barcodes"
|
|
||||||
],
|
|
||||||
"summary": "Generate barcodes",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"enum": [
|
|
||||||
"ean13",
|
|
||||||
"code128"
|
|
||||||
],
|
|
||||||
"type": "string",
|
|
||||||
"description": "Barcode type",
|
|
||||||
"name": "type",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"minLength": 1,
|
|
||||||
"type": "string",
|
|
||||||
"description": "Barcode content",
|
|
||||||
"name": "content",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/v1/pdfs/cards": {
|
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"ApiKeyAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Generate cards based on the provided data",
|
"description": "Generate cards based on the provided data",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -63,7 +24,7 @@
|
|||||||
"application/pdf"
|
"application/pdf"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"pdfs"
|
"cards"
|
||||||
],
|
],
|
||||||
"summary": "Generate runner cards",
|
"summary": "Generate runner cards",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@ -80,13 +41,8 @@
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/v1/pdfs/certificates": {
|
"/certificates": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"ApiKeyAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Generate certificates based on the provided data",
|
"description": "Generate certificates based on the provided data",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -95,7 +51,7 @@
|
|||||||
"application/pdf"
|
"application/pdf"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"pdfs"
|
"certificates"
|
||||||
],
|
],
|
||||||
"summary": "Generate runner certificates",
|
"summary": "Generate runner certificates",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@ -112,13 +68,8 @@
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/v1/pdfs/contracts": {
|
"/contracts": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"ApiKeyAuth": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Generate a contract based on the provided data",
|
"description": "Generate a contract based on the provided data",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -127,7 +78,7 @@
|
|||||||
"application/pdf"
|
"application/pdf"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"pdfs"
|
"contracts"
|
||||||
],
|
],
|
||||||
"summary": "Generate a contract",
|
"summary": "Generate a contract",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@ -375,5 +326,10 @@
|
|||||||
"name": "key",
|
"name": "key",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}
|
}
|
@ -163,31 +163,7 @@ info:
|
|||||||
termsOfService: https://lauf-fuer-kaya.de/datenschutz
|
termsOfService: https://lauf-fuer-kaya.de/datenschutz
|
||||||
title: LfK Document Server API
|
title: LfK Document Server API
|
||||||
paths:
|
paths:
|
||||||
/v1/barcodes/{type}/{content}:
|
/cards:
|
||||||
get:
|
|
||||||
description: Generate barcodes based on the provided data
|
|
||||||
parameters:
|
|
||||||
- description: Barcode type
|
|
||||||
enum:
|
|
||||||
- ean13
|
|
||||||
- code128
|
|
||||||
in: path
|
|
||||||
name: type
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Barcode content
|
|
||||||
in: path
|
|
||||||
minLength: 1
|
|
||||||
name: content
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
produces:
|
|
||||||
- image/png
|
|
||||||
responses: {}
|
|
||||||
summary: Generate barcodes
|
|
||||||
tags:
|
|
||||||
- barcodes
|
|
||||||
/v1/pdfs/cards:
|
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
@ -202,12 +178,10 @@ paths:
|
|||||||
produces:
|
produces:
|
||||||
- application/pdf
|
- application/pdf
|
||||||
responses: {}
|
responses: {}
|
||||||
security:
|
|
||||||
- ApiKeyAuth: []
|
|
||||||
summary: Generate runner cards
|
summary: Generate runner cards
|
||||||
tags:
|
tags:
|
||||||
- pdfs
|
- cards
|
||||||
/v1/pdfs/certificates:
|
/certificates:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
@ -222,12 +196,10 @@ paths:
|
|||||||
produces:
|
produces:
|
||||||
- application/pdf
|
- application/pdf
|
||||||
responses: {}
|
responses: {}
|
||||||
security:
|
|
||||||
- ApiKeyAuth: []
|
|
||||||
summary: Generate runner certificates
|
summary: Generate runner certificates
|
||||||
tags:
|
tags:
|
||||||
- pdfs
|
- certificates
|
||||||
/v1/pdfs/contracts:
|
/contracts:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
@ -242,11 +214,11 @@ paths:
|
|||||||
produces:
|
produces:
|
||||||
- application/pdf
|
- application/pdf
|
||||||
responses: {}
|
responses: {}
|
||||||
security:
|
|
||||||
- ApiKeyAuth: []
|
|
||||||
summary: Generate a contract
|
summary: Generate a contract
|
||||||
tags:
|
tags:
|
||||||
- pdfs
|
- contracts
|
||||||
|
security:
|
||||||
|
- ApiKeyAuth: []
|
||||||
securityDefinitions:
|
securityDefinitions:
|
||||||
ApiKeyAuth:
|
ApiKeyAuth:
|
||||||
in: query
|
in: query
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GenerateBarcode godoc
|
|
||||||
//
|
|
||||||
// @Summary Generate barcodes
|
|
||||||
// @Description Generate barcodes based on the provided data
|
|
||||||
// @Tags barcodes
|
|
||||||
// @Param type path string true "Barcode type" Enums(ean13, code128)
|
|
||||||
// @Param content path string true "Barcode content" MinLength(1)
|
|
||||||
// @Produce image/png
|
|
||||||
// @Router /v1/barcodes/{type}/{content} [get]
|
|
||||||
func (h *DefaultHandler) GenerateBarcode(c *fiber.Ctx) error {
|
|
||||||
|
|
||||||
// Get the type and content from the URL
|
|
||||||
barcodeType := c.Params("type")
|
|
||||||
barcodeContent := c.Params("content")
|
|
||||||
|
|
||||||
// Generate the barcode
|
|
||||||
barcode, err := h.BarcodeService.GenerateBarcode(barcodeType, barcodeContent, 1000, 1000)
|
|
||||||
if err != nil {
|
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
||||||
"error": err.Error(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Set(fiber.HeaderContentType, "image/png")
|
|
||||||
return c.Send(barcode.Bytes())
|
|
||||||
}
|
|
@ -10,15 +10,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GenerateCard godoc
|
// GenerateCard godoc
|
||||||
//
|
|
||||||
// @Summary Generate runner cards
|
// @Summary Generate runner cards
|
||||||
// @Description Generate cards based on the provided data
|
// @Description Generate cards based on the provided data
|
||||||
// @Tags pdfs
|
// @Tags cards
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Param data body models.CardRequest true "Card data"
|
// @Param data body models.CardRequest true "Card data"
|
||||||
// @Produce application/pdf
|
// @Produce application/pdf
|
||||||
// @Security ApiKeyAuth
|
// @Router /cards [post]
|
||||||
// @Router /v1/pdfs/cards [post]
|
|
||||||
func (h *DefaultHandler) GenerateCard(c *fiber.Ctx) error {
|
func (h *DefaultHandler) GenerateCard(c *fiber.Ctx) error {
|
||||||
cardRequest := new(models.CardRequest)
|
cardRequest := new(models.CardRequest)
|
||||||
if err := c.BodyParser(cardRequest); err != nil {
|
if err := c.BodyParser(cardRequest); err != nil {
|
||||||
@ -32,6 +30,7 @@ func (h *DefaultHandler) GenerateCard(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generator := services.DefaultTemplater{}
|
||||||
templateString, err := services.GetTemplate(cardRequest.Locale, "card")
|
templateString, err := services.GetTemplate(cardRequest.Locale, "card")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -39,7 +38,7 @@ func (h *DefaultHandler) GenerateCard(c *fiber.Ctx) error {
|
|||||||
"error": "Template not found",
|
"error": "Template not found",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
template, err := h.Templater.StringToTemplate(templateString)
|
template, err := generator.StringToTemplate(templateString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
@ -54,15 +53,15 @@ func (h *DefaultHandler) GenerateCard(c *fiber.Ctx) error {
|
|||||||
BarcodePrefix: h.Config.CardBarcodePrefix,
|
BarcodePrefix: h.Config.CardBarcodePrefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.Templater.Execute(template, genConfig)
|
result, err := generator.Execute(template, genConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
c.Set(fiber.HeaderContentType, "text/html")
|
c.Set(fiber.HeaderContentType, "text/html")
|
||||||
|
converter := services.GotenbergConverter{BaseUrl: h.Config.GotenbergBaseUrl}
|
||||||
pdf, err := h.Converter.ToPdf(result, "a4", false)
|
pdf, err := converter.ToPdf(result, "a4", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
@ -10,15 +10,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GenerateCertificate godoc
|
// GenerateCertificate godoc
|
||||||
//
|
|
||||||
// @Summary Generate runner certificates
|
// @Summary Generate runner certificates
|
||||||
// @Description Generate certificates based on the provided data
|
// @Description Generate certificates based on the provided data
|
||||||
// @Tags pdfs
|
// @Tags certificates
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Param data body models.CertificateRequest true "Certificate data"
|
// @Param data body models.CertificateRequest true "Certificate data"
|
||||||
// @Produce application/pdf
|
// @Produce application/pdf
|
||||||
// @Security ApiKeyAuth
|
// @Router /certificates [post]
|
||||||
// @Router /v1/pdfs/certificates [post]
|
|
||||||
func (h *DefaultHandler) GenerateCertificate(c *fiber.Ctx) error {
|
func (h *DefaultHandler) GenerateCertificate(c *fiber.Ctx) error {
|
||||||
certificateRequest := new(models.CertificateRequest)
|
certificateRequest := new(models.CertificateRequest)
|
||||||
if err := c.BodyParser(certificateRequest); err != nil {
|
if err := c.BodyParser(certificateRequest); err != nil {
|
||||||
@ -32,6 +30,7 @@ func (h *DefaultHandler) GenerateCertificate(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generator := services.DefaultTemplater{}
|
||||||
templateString, err := services.GetTemplate(certificateRequest.Locale, "certificate")
|
templateString, err := services.GetTemplate(certificateRequest.Locale, "certificate")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -39,7 +38,7 @@ func (h *DefaultHandler) GenerateCertificate(c *fiber.Ctx) error {
|
|||||||
"error": "Template not found",
|
"error": "Template not found",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
template, err := h.Templater.StringToTemplate(templateString)
|
template, err := generator.StringToTemplate(templateString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
@ -54,15 +53,15 @@ func (h *DefaultHandler) GenerateCertificate(c *fiber.Ctx) error {
|
|||||||
Locale: certificateRequest.Locale,
|
Locale: certificateRequest.Locale,
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.Templater.Execute(template, genConfig)
|
result, err := generator.Execute(template, genConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
c.Set(fiber.HeaderContentType, "text/html")
|
c.Set(fiber.HeaderContentType, "text/html")
|
||||||
|
converter := services.GotenbergConverter{BaseUrl: h.Config.GotenbergBaseUrl}
|
||||||
pdf, err := h.Converter.ToPdf(result, "a4", false)
|
pdf, err := converter.ToPdf(result, "a4", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
@ -10,15 +10,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GenerateContract godoc
|
// GenerateContract godoc
|
||||||
//
|
|
||||||
// @Summary Generate a contract
|
// @Summary Generate a contract
|
||||||
// @Description Generate a contract based on the provided data
|
// @Description Generate a contract based on the provided data
|
||||||
// @Tags pdfs
|
// @Tags contracts
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Param data body models.ContractRequest true "Contract data"
|
// @Param data body models.ContractRequest true "Contract data"
|
||||||
// @Produce application/pdf
|
// @Produce application/pdf
|
||||||
// @Security ApiKeyAuth
|
// @Router /contracts [post]
|
||||||
// @Router /v1/pdfs/contracts [post]
|
|
||||||
func (h *DefaultHandler) GenerateContract(c *fiber.Ctx) error {
|
func (h *DefaultHandler) GenerateContract(c *fiber.Ctx) error {
|
||||||
contract := new(models.ContractRequest)
|
contract := new(models.ContractRequest)
|
||||||
if err := c.BodyParser(contract); err != nil {
|
if err := c.BodyParser(contract); err != nil {
|
||||||
@ -34,6 +32,7 @@ func (h *DefaultHandler) GenerateContract(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
contract.Runners = repeatRunnerArrayItems(contract.Runners, 2)
|
contract.Runners = repeatRunnerArrayItems(contract.Runners, 2)
|
||||||
|
|
||||||
|
generator := services.DefaultTemplater{}
|
||||||
templateString, err := services.GetTemplate(contract.Locale, "contract")
|
templateString, err := services.GetTemplate(contract.Locale, "contract")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -41,7 +40,7 @@ func (h *DefaultHandler) GenerateContract(c *fiber.Ctx) error {
|
|||||||
"error": "Template not found",
|
"error": "Template not found",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
template, err := h.Templater.StringToTemplate(templateString)
|
template, err := generator.StringToTemplate(templateString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
@ -58,14 +57,15 @@ func (h *DefaultHandler) GenerateContract(c *fiber.Ctx) error {
|
|||||||
BarcodePrefix: h.Config.SponsoringBarcodePrefix,
|
BarcodePrefix: h.Config.SponsoringBarcodePrefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.Templater.Execute(template, genConfig)
|
result, err := generator.Execute(template, genConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pdf, err := h.Converter.ToPdf(result, "a5", true)
|
converter := services.GotenbergConverter{BaseUrl: h.Config.GotenbergBaseUrl}
|
||||||
|
pdf, err := converter.ToPdf(result, "a5", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
@ -2,7 +2,6 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.odit.services/lfk/document-server/models"
|
"git.odit.services/lfk/document-server/models"
|
||||||
"git.odit.services/lfk/document-server/services"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,12 +9,8 @@ type Handler interface {
|
|||||||
GenerateCard(*fiber.Ctx) error
|
GenerateCard(*fiber.Ctx) error
|
||||||
GenerateContract(*fiber.Ctx) error
|
GenerateContract(*fiber.Ctx) error
|
||||||
GenerateCertificate(*fiber.Ctx) error
|
GenerateCertificate(*fiber.Ctx) error
|
||||||
GenerateBarcode(*fiber.Ctx) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DefaultHandler struct {
|
type DefaultHandler struct {
|
||||||
Config *models.Config
|
Config *models.Config
|
||||||
BarcodeService services.BarcodeService
|
|
||||||
Templater services.Templater
|
|
||||||
Converter services.Converter
|
|
||||||
}
|
}
|
||||||
|
25
main.go
25
main.go
@ -8,7 +8,6 @@ import (
|
|||||||
"git.odit.services/lfk/document-server/docs" // Correct import path for docs
|
"git.odit.services/lfk/document-server/docs" // Correct import path for docs
|
||||||
"git.odit.services/lfk/document-server/handlers"
|
"git.odit.services/lfk/document-server/handlers"
|
||||||
"git.odit.services/lfk/document-server/models"
|
"git.odit.services/lfk/document-server/models"
|
||||||
"git.odit.services/lfk/document-server/services"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/keyauth"
|
"github.com/gofiber/fiber/v2/middleware/keyauth"
|
||||||
"github.com/gofiber/swagger"
|
"github.com/gofiber/swagger"
|
||||||
@ -73,16 +72,8 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
barcodeGenerator := &services.DefaultBarcodeService{}
|
|
||||||
handler := handlers.DefaultHandler{
|
handler := handlers.DefaultHandler{
|
||||||
Config: config,
|
Config: config,
|
||||||
BarcodeService: barcodeGenerator,
|
|
||||||
Templater: &services.DefaultTemplater{
|
|
||||||
BarcodeService: barcodeGenerator,
|
|
||||||
},
|
|
||||||
Converter: &services.GotenbergConverter{
|
|
||||||
BaseUrl: config.GotenbergBaseUrl,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new Fiber instance
|
// Create a new Fiber instance
|
||||||
@ -93,19 +84,19 @@ func main() {
|
|||||||
// Swagger documentation route
|
// Swagger documentation route
|
||||||
app.Get("/swagger/*", swagger.HandlerDefault)
|
app.Get("/swagger/*", swagger.HandlerDefault)
|
||||||
|
|
||||||
|
// @Security ApiKeyAuth
|
||||||
v1 := app.Group("/v1")
|
v1 := app.Group("/v1")
|
||||||
|
v1.Use(keyauth.New(keyauth.Config{
|
||||||
pdfv1 := v1.Group("/pdfs")
|
|
||||||
pdfv1.Use(keyauth.New(keyauth.Config{
|
|
||||||
KeyLookup: "query:key",
|
KeyLookup: "query:key",
|
||||||
Validator: validateAPIKey,
|
Validator: validateAPIKey,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
pdfv1.Post("/contracts", handler.GenerateContract)
|
v1.Get("/", func(c *fiber.Ctx) error {
|
||||||
pdfv1.Post("/cards", handler.GenerateCard)
|
return c.SendString("Hello, World!")
|
||||||
pdfv1.Post("/certificates", handler.GenerateCertificate)
|
})
|
||||||
|
v1.Post("/contracts", handler.GenerateContract)
|
||||||
v1.Get("/barcodes/:type/:content", handler.GenerateBarcode)
|
v1.Post("/cards", handler.GenerateCard)
|
||||||
|
v1.Post("/certificates", handler.GenerateCertificate)
|
||||||
|
|
||||||
app.Use(handler.NotFoundHandler)
|
app.Use(handler.NotFoundHandler)
|
||||||
docs.SwaggerInfo.BasePath = "/"
|
docs.SwaggerInfo.BasePath = "/"
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
package services
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"image/png"
|
|
||||||
"slices"
|
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
|
||||||
"github.com/boombuler/barcode/code128"
|
|
||||||
"github.com/boombuler/barcode/ean"
|
|
||||||
"github.com/boombuler/barcode/qr"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BarcodeService interface {
|
|
||||||
GenerateBarcode(format string, content string, width int, height int) (bytes.Buffer, error)
|
|
||||||
IsTypeSupported(format string) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type DefaultBarcodeService struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *DefaultBarcodeService) GenerateBarcode(format string, content string, width int, height int) (bytes.Buffer, error) {
|
|
||||||
if !b.IsTypeSupported(format) {
|
|
||||||
return bytes.Buffer{}, fmt.Errorf("unsupported barcode type: %s", format)
|
|
||||||
}
|
|
||||||
|
|
||||||
var generatedCode barcode.Barcode
|
|
||||||
var err error
|
|
||||||
|
|
||||||
switch format {
|
|
||||||
case "ean13":
|
|
||||||
generatedCode, err = ean.Encode(content)
|
|
||||||
if err != nil {
|
|
||||||
return bytes.Buffer{}, err
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "code128":
|
|
||||||
generatedCode, err = code128.Encode(content)
|
|
||||||
if err != nil {
|
|
||||||
return bytes.Buffer{}, err
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "qr":
|
|
||||||
generatedCode, err = qr.Encode(content, qr.M, qr.AlphaNumeric)
|
|
||||||
if err != nil {
|
|
||||||
return bytes.Buffer{}, err
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
scaledCode, err := barcode.Scale(generatedCode, width, height)
|
|
||||||
if err != nil {
|
|
||||||
return bytes.Buffer{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
err = png.Encode(&buf, scaledCode)
|
|
||||||
if err != nil {
|
|
||||||
return bytes.Buffer{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *DefaultBarcodeService) IsTypeSupported(format string) bool {
|
|
||||||
supportedTypes := []string{"ean13", "code128", "qr"}
|
|
||||||
return slices.Contains(supportedTypes, format)
|
|
||||||
}
|
|
@ -6,7 +6,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"image/png"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/boombuler/barcode"
|
||||||
|
"github.com/boombuler/barcode/code128"
|
||||||
|
"github.com/boombuler/barcode/ean"
|
||||||
|
"github.com/boombuler/barcode/qr"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Templater interface {
|
type Templater interface {
|
||||||
@ -15,7 +21,6 @@ type Templater interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DefaultTemplater struct {
|
type DefaultTemplater struct {
|
||||||
BarcodeService BarcodeService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func idToEan13(id string, prefix string) (string, error) {
|
func idToEan13(id string, prefix string) (string, error) {
|
||||||
@ -32,18 +37,48 @@ func idToEan13(id string, prefix string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix string) (string, error) {
|
func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix string) (string, error) {
|
||||||
|
var generatedCode barcode.Barcode
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if format == "ean13" {
|
switch format {
|
||||||
code, err = idToEan13(code, prefix)
|
case "ean13":
|
||||||
|
encodedEan, err := idToEan13(code, prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
generatedCode, err = ean.Encode(encodedEan)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "code128":
|
||||||
|
generatedCode, err = code128.Encode(prefix + code)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "qr":
|
||||||
|
generatedCode, err = qr.Encode(prefix+code, qr.M, qr.AlphaNumeric)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return "", errors.New("unknown barcode format")
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := t.BarcodeService.GenerateBarcode(format, code, 1000, 500)
|
scaledCode, err := barcode.Scale(generatedCode, 1000, 500)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
return base64.StdEncoding.EncodeToString(buf.Bytes()), err
|
var buf bytes.Buffer
|
||||||
|
err = png.Encode(&buf, scaledCode)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user