mirror of https://github.com/stashapp/stash.git
56 lines
926 B
Go
56 lines
926 B
Go
package tag
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
)
|
|
|
|
func ByName(ctx context.Context, qb models.TagQueryer, name string) (*models.Tag, error) {
|
|
f := &models.TagFilterType{
|
|
Name: &models.StringCriterionInput{
|
|
Value: name,
|
|
Modifier: models.CriterionModifierEquals,
|
|
},
|
|
}
|
|
|
|
pp := 1
|
|
ret, count, err := qb.Query(ctx, f, &models.FindFilterType{
|
|
PerPage: &pp,
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if count > 0 {
|
|
return ret[0], nil
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func ByAlias(ctx context.Context, qb models.TagQueryer, alias string) (*models.Tag, error) {
|
|
f := &models.TagFilterType{
|
|
Aliases: &models.StringCriterionInput{
|
|
Value: alias,
|
|
Modifier: models.CriterionModifierEquals,
|
|
},
|
|
}
|
|
|
|
pp := 1
|
|
ret, count, err := qb.Query(ctx, f, &models.FindFilterType{
|
|
PerPage: &pp,
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if count > 0 {
|
|
return ret[0], nil
|
|
}
|
|
|
|
return nil, nil
|
|
}
|