feat(handlers): Implement barcode generation

This commit is contained in:
2024-12-12 16:49:33 +01:00
parent b6cc98a165
commit 0f2452eca0
5 changed files with 40 additions and 20 deletions

View File

@@ -12,15 +12,15 @@ import (
"github.com/boombuler/barcode/qr"
)
type BarcodeGenerator interface {
GenerateBarcode(format string, content string) (bytes.Buffer, error)
type BarcodeService interface {
GenerateBarcode(format string, content string, width int, height int) (bytes.Buffer, error)
IsTypeSupported(format string) bool
}
type DefaultBarcodeGenerator struct {
type DefaultBarcodeService struct {
}
func (b *DefaultBarcodeGenerator) GenerateBarcode(format string, content string, width int, height int) (bytes.Buffer, error) {
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)
}
@@ -63,7 +63,7 @@ func (b *DefaultBarcodeGenerator) GenerateBarcode(format string, content string,
return buf, nil
}
func (b *DefaultBarcodeGenerator) IsTypeSupported(format string) bool {
func (b *DefaultBarcodeService) IsTypeSupported(format string) bool {
supportedTypes := []string{"ean13", "code128", "qr"}
return slices.Contains(supportedTypes, format)
}

View File

@@ -31,7 +31,7 @@ func idToEan13(id string, prefix string) (string, error) {
}
func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix string) (string, error) {
gen := &DefaultBarcodeGenerator{}
gen := &DefaultBarcodeService{}
var err error
if format == "ean13" {