48 lines
922 B
Go
48 lines
922 B
Go
package useCases
|
|
|
|
import (
|
|
"RenewCMS/internal/domain/audit"
|
|
"RenewCMS/internal/domain/image"
|
|
"RenewCMS/internal/domain/site"
|
|
"errors"
|
|
"strconv"
|
|
)
|
|
|
|
func siteTarget(s site.Site) audit.Target {
|
|
return audit.NewTarget(audit.TargetSite, s.ID, s.Name)
|
|
}
|
|
|
|
func ensureImageExists(images image.Repository, id *uint32) error {
|
|
if id == nil {
|
|
return nil
|
|
}
|
|
_, err := images.Get(*id)
|
|
return err
|
|
}
|
|
|
|
func isKeyTaken(sites site.Repository, key string) (bool, error) {
|
|
_, err := sites.GetByKey(key)
|
|
if errors.Is(err, site.ErrSiteNotFound) {
|
|
return false, nil
|
|
}
|
|
return err == nil, err
|
|
}
|
|
|
|
func imageLabel(images image.Repository, id *uint32) string {
|
|
if id == nil {
|
|
return ""
|
|
}
|
|
found, err := images.Get(*id)
|
|
if err != nil || found.Filename == "" {
|
|
return strconv.FormatUint(uint64(*id), 10)
|
|
}
|
|
return found.Filename
|
|
}
|
|
|
|
func localeLabel(locale *string) string {
|
|
if locale == nil {
|
|
return ""
|
|
}
|
|
return *locale
|
|
}
|