2021-05-26 04:36:05 +00:00
|
|
|
package tag
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2021-05-26 04:36:05 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
)
|
|
|
|
|
2023-09-01 00:39:29 +00:00
|
|
|
func ByName(ctx context.Context, qb models.TagQueryer, name string) (*models.Tag, error) {
|
2021-05-26 04:36:05 +00:00
|
|
|
f := &models.TagFilterType{
|
|
|
|
Name: &models.StringCriterionInput{
|
|
|
|
Value: name,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
pp := 1
|
2022-05-19 07:49:32 +00:00
|
|
|
ret, count, err := qb.Query(ctx, f, &models.FindFilterType{
|
2021-05-26 04:36:05 +00:00
|
|
|
PerPage: &pp,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 0 {
|
|
|
|
return ret[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-09-01 00:39:29 +00:00
|
|
|
func ByAlias(ctx context.Context, qb models.TagQueryer, alias string) (*models.Tag, error) {
|
2021-05-26 04:36:05 +00:00
|
|
|
f := &models.TagFilterType{
|
|
|
|
Aliases: &models.StringCriterionInput{
|
|
|
|
Value: alias,
|
|
|
|
Modifier: models.CriterionModifierEquals,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
pp := 1
|
2022-05-19 07:49:32 +00:00
|
|
|
ret, count, err := qb.Query(ctx, f, &models.FindFilterType{
|
2021-05-26 04:36:05 +00:00
|
|
|
PerPage: &pp,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 0 {
|
|
|
|
return ret[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|