stash/pkg/studio/query.go
bob123491234 b3d35dfae4
Add tags to studios (#4858)
* Fix makeTagFilter mode

* Remove studio_tags filter criterion

This is handled by studios_filter. The support for this still needs to be added in the UI, so I have removed the criterion options in the short-term.
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2024-06-18 15:55:20 +10:00

68 lines
1.3 KiB
Go

package studio
import (
"context"
"strconv"
"github.com/stashapp/stash/pkg/models"
)
func ByName(ctx context.Context, qb models.StudioQueryer, name string) (*models.Studio, error) {
f := &models.StudioFilterType{
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.StudioQueryer, alias string) (*models.Studio, error) {
f := &models.StudioFilterType{
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
}
func CountByTagID(ctx context.Context, qb models.StudioQueryer, id int, depth *int) (int, error) {
filter := &models.StudioFilterType{
Tags: &models.HierarchicalMultiCriterionInput{
Value: []string{strconv.Itoa(id)},
Modifier: models.CriterionModifierIncludes,
Depth: depth,
},
}
return qb.QueryCount(ctx, filter, nil)
}