2020-07-07 00:35:43 +00:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
)
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
func EnsureTagNameUnique(tag models.Tag, qb models.TagReader) error {
|
2020-07-07 00:35:43 +00:00
|
|
|
// ensure name is unique
|
2021-01-18 01:23:20 +00:00
|
|
|
sameNameTag, err := qb.FindByName(tag.Name, true)
|
2020-07-07 00:35:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-02 00:30:37 +00:00
|
|
|
if sameNameTag != nil && tag.ID != sameNameTag.ID {
|
|
|
|
return fmt.Errorf("Tag with name '%s' already exists", tag.Name)
|
2020-07-07 00:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|