2021-09-09 08:13:42 +00:00
|
|
|
package studio
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2021-09-09 08:13:42 +00:00
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Finder interface {
|
|
|
|
Find(ctx context.Context, id int) (*models.Studio, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Queryer interface {
|
|
|
|
Query(ctx context.Context, studioFilter *models.StudioFilterType, findFilter *models.FindFilterType) ([]*models.Studio, int, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ByName(ctx context.Context, qb Queryer, name string) (*models.Studio, error) {
|
2021-09-09 08:13:42 +00:00
|
|
|
f := &models.StudioFilterType{
|
|
|
|
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-09-09 08:13:42 +00:00
|
|
|
PerPage: &pp,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 0 {
|
|
|
|
return ret[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:49:32 +00:00
|
|
|
func ByAlias(ctx context.Context, qb Queryer, alias string) (*models.Studio, error) {
|
2021-09-09 08:13:42 +00:00
|
|
|
f := &models.StudioFilterType{
|
|
|
|
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-09-09 08:13:42 +00:00
|
|
|
PerPage: &pp,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 0 {
|
|
|
|
return ret[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|