refactor(services): Move staticservice to struct and interface

This commit is contained in:
2024-12-12 17:11:59 +01:00
parent 2a4f126377
commit b9e550d6f5
7 changed files with 23 additions and 12 deletions

View File

@@ -16,6 +16,7 @@ type Templater interface {
type DefaultTemplater struct {
BarcodeService BarcodeService
StaticService StaticService
}
func idToEan13(id string, prefix string) (string, error) {
@@ -47,15 +48,15 @@ func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix st
}
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
sponsors, err := ListFilesInStaticSubFolder("images/sponsors")
sponsors, err := t.StaticService.ListFilesInStaticSubFolder("images/sponsors")
if err != nil {
return "", err
}
return GetImage("sponsors/" + strings.TrimSuffix(sponsors[id%len(sponsors)], ".base64")), nil
return t.StaticService.GetImage("sponsors/" + strings.TrimSuffix(sponsors[id%len(sponsors)], ".base64")), nil
}
func (t *DefaultTemplater) LoadImage(name string) (string, error) {
return GetImage(name), nil
return t.StaticService.GetImage(name), nil
}
func (t *DefaultTemplater) FormatUnit(unit string, locale string, amount int) (string, error) {