-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
resolver_model_studio.go
77 lines (61 loc) · 1.97 KB
/
resolver_model_studio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package api
import (
"context"
"time"
"github.com/stashapp/stash-box/pkg/dataloader"
"github.com/stashapp/stash-box/pkg/models"
)
type studioResolver struct{ *Resolver }
func (r *studioResolver) ID(ctx context.Context, obj *models.Studio) (string, error) {
return obj.ID.String(), nil
}
func (r *studioResolver) Urls(ctx context.Context, obj *models.Studio) ([]*models.URL, error) {
return dataloader.For(ctx).StudioUrlsByID.Load(obj.ID)
}
func (r *studioResolver) Parent(ctx context.Context, obj *models.Studio) (*models.Studio, error) {
if !obj.ParentStudioID.Valid {
return nil, nil
}
qb := r.getRepoFactory(ctx).Studio()
parent, err := qb.Find(obj.ParentStudioID.UUID)
if err != nil {
return nil, err
}
return parent, nil
}
func (r *studioResolver) ChildStudios(ctx context.Context, obj *models.Studio) ([]*models.Studio, error) {
qb := r.getRepoFactory(ctx).Studio()
children, err := qb.FindByParentID(obj.ID)
if err != nil {
return nil, err
}
return children, nil
}
func (r *studioResolver) Images(ctx context.Context, obj *models.Studio) ([]*models.Image, error) {
imageIDs, err := dataloader.For(ctx).StudioImageIDsByID.Load(obj.ID)
if err != nil {
return nil, err
}
images, errors := dataloader.For(ctx).ImageByID.LoadAll(imageIDs)
for _, err := range errors {
if err != nil {
return nil, err
}
}
return images, nil
}
func (r *studioResolver) IsFavorite(ctx context.Context, obj *models.Studio) (bool, error) {
return dataloader.For(ctx).StudioIsFavoriteByID.Load(obj.ID)
}
func (r *studioResolver) Created(ctx context.Context, obj *models.Studio) (*time.Time, error) {
return &obj.CreatedAt, nil
}
func (r *studioResolver) Updated(ctx context.Context, obj *models.Studio) (*time.Time, error) {
return &obj.UpdatedAt, nil
}
func (r *studioResolver) Performers(ctx context.Context, obj *models.Studio, input models.PerformerQueryInput) (*models.PerformerQuery, error) {
input.StudioID = &obj.ID
return &models.PerformerQuery{
Filter: input,
}, nil
}