2019-02-09 12:30:49 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-02-14 23:42:52 +00:00
|
|
|
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2019-02-09 12:30:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (r *studioResolver) Name(ctx context.Context, obj *models.Studio) (string, error) {
|
|
|
|
if obj.Name.Valid {
|
|
|
|
return obj.Name.String, nil
|
|
|
|
}
|
|
|
|
panic("null name") // TODO make name required
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *studioResolver) URL(ctx context.Context, obj *models.Studio) (*string, error) {
|
2019-02-14 22:53:32 +00:00
|
|
|
if obj.URL.Valid {
|
|
|
|
return &obj.URL.String, nil
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *studioResolver) ImagePath(ctx context.Context, obj *models.Studio) (*string, error) {
|
|
|
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
2019-02-14 22:53:32 +00:00
|
|
|
imagePath := urlbuilders.NewStudioURLBuilder(baseURL, obj.ID).GetStudioImageURL()
|
2019-02-09 12:30:49 +00:00
|
|
|
return &imagePath, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *studioResolver) SceneCount(ctx context.Context, obj *models.Studio) (*int, error) {
|
|
|
|
qb := models.NewSceneQueryBuilder()
|
|
|
|
res, err := qb.CountByStudioID(obj.ID)
|
|
|
|
return &res, err
|
|
|
|
}
|