feat(handlers): Implement barcode generation
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user