feat(barcodes): Make width and height configureable
This commit is contained in:
parent
5c932158e9
commit
2a4f126377
18
docs/docs.go
18
docs/docs.go
@ -52,6 +52,24 @@ const docTemplate = `{
|
|||||||
"name": "content",
|
"name": "content",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 10000,
|
||||||
|
"minimum": 1,
|
||||||
|
"type": "integer",
|
||||||
|
"default": 1000,
|
||||||
|
"description": "Barcode width",
|
||||||
|
"name": "width",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 10000,
|
||||||
|
"minimum": 1,
|
||||||
|
"type": "integer",
|
||||||
|
"default": 1000,
|
||||||
|
"description": "Barcode height",
|
||||||
|
"name": "height",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {}
|
"responses": {}
|
||||||
|
@ -43,6 +43,24 @@
|
|||||||
"name": "content",
|
"name": "content",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 10000,
|
||||||
|
"minimum": 1,
|
||||||
|
"type": "integer",
|
||||||
|
"default": 1000,
|
||||||
|
"description": "Barcode width",
|
||||||
|
"name": "width",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 10000,
|
||||||
|
"minimum": 1,
|
||||||
|
"type": "integer",
|
||||||
|
"default": 1000,
|
||||||
|
"description": "Barcode height",
|
||||||
|
"name": "height",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {}
|
"responses": {}
|
||||||
|
@ -181,6 +181,20 @@ paths:
|
|||||||
name: content
|
name: content
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
- default: 1000
|
||||||
|
description: Barcode width
|
||||||
|
in: query
|
||||||
|
maximum: 10000
|
||||||
|
minimum: 1
|
||||||
|
name: width
|
||||||
|
type: integer
|
||||||
|
- default: 1000
|
||||||
|
description: Barcode height
|
||||||
|
in: query
|
||||||
|
maximum: 10000
|
||||||
|
minimum: 1
|
||||||
|
name: height
|
||||||
|
type: integer
|
||||||
produces:
|
produces:
|
||||||
- image/png
|
- image/png
|
||||||
responses: {}
|
responses: {}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,6 +13,8 @@ import (
|
|||||||
// @Tags barcodes
|
// @Tags barcodes
|
||||||
// @Param type path string true "Barcode type" Enums(ean13, code128)
|
// @Param type path string true "Barcode type" Enums(ean13, code128)
|
||||||
// @Param content path string true "Barcode content" MinLength(1)
|
// @Param content path string true "Barcode content" MinLength(1)
|
||||||
|
// @Param width query int false "Barcode width" Minimum(1) Maximum(10000) default(1000)
|
||||||
|
// @Param height query int false "Barcode height" Minimum(1) Maximum(10000) default(1000)
|
||||||
// @Produce image/png
|
// @Produce image/png
|
||||||
// @Router /v1/barcodes/{type}/{content} [get]
|
// @Router /v1/barcodes/{type}/{content} [get]
|
||||||
func (h *DefaultHandler) GenerateBarcode(c *fiber.Ctx) error {
|
func (h *DefaultHandler) GenerateBarcode(c *fiber.Ctx) error {
|
||||||
@ -19,8 +23,27 @@ func (h *DefaultHandler) GenerateBarcode(c *fiber.Ctx) error {
|
|||||||
barcodeType := c.Params("type")
|
barcodeType := c.Params("type")
|
||||||
barcodeContent := c.Params("content")
|
barcodeContent := c.Params("content")
|
||||||
|
|
||||||
|
// Get the width and height from the query parameters
|
||||||
|
widthStr := c.Query("width", "1000")
|
||||||
|
heightStr := c.Query("height", "1000")
|
||||||
|
|
||||||
|
// Convert width and height to integers
|
||||||
|
width, err := strconv.Atoi(widthStr)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"error": "Invalid width parameter",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
height, err := strconv.Atoi(heightStr)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"error": "Invalid height parameter",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Generate the barcode
|
// Generate the barcode
|
||||||
barcode, err := h.BarcodeService.GenerateBarcode(barcodeType, barcodeContent, 1000, 1000)
|
barcode, err := h.BarcodeService.GenerateBarcode(barcodeType, barcodeContent, width, height)
|
||||||
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(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user