Skip to content

Commit 2a2a730

Browse files
authored
Add interface for bulk update studio (#6208)
1 parent beee37b commit 2a2a730

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

graphql/schema/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ type Mutation {
371371
studioUpdate(input: StudioUpdateInput!): Studio
372372
studioDestroy(input: StudioDestroyInput!): Boolean!
373373
studiosDestroy(ids: [ID!]!): Boolean!
374+
bulkStudioUpdate(input: BulkStudioUpdateInput!): [Studio!]
374375

375376
movieCreate(input: MovieCreateInput!): Movie
376377
@deprecated(reason: "Use groupCreate instead")

graphql/schema/types/studio.graphql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ input StudioUpdateInput {
5959
ignore_auto_tag: Boolean
6060
}
6161

62+
input BulkStudioUpdateInput {
63+
ids: [ID!]!
64+
url: String
65+
parent_id: ID
66+
# rating expressed as 1-100
67+
rating100: Int
68+
favorite: Boolean
69+
details: String
70+
tag_ids: BulkUpdateIds
71+
ignore_auto_tag: Boolean
72+
}
73+
6274
input StudioDestroyInput {
6375
id: ID!
6476
}

internal/api/resolver_mutation_studio.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,77 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
163163
return r.getStudio(ctx, studioID)
164164
}
165165

166+
func (r *mutationResolver) BulkStudioUpdate(ctx context.Context, input BulkStudioUpdateInput) ([]*models.Studio, error) {
167+
ids, err := stringslice.StringSliceToIntSlice(input.Ids)
168+
if err != nil {
169+
return nil, fmt.Errorf("converting ids: %w", err)
170+
}
171+
172+
translator := changesetTranslator{
173+
inputMap: getUpdateInputMap(ctx),
174+
}
175+
176+
// Populate performer from the input
177+
partial := models.NewStudioPartial()
178+
179+
partial.ParentID, err = translator.optionalIntFromString(input.ParentID, "parent_id")
180+
if err != nil {
181+
return nil, fmt.Errorf("converting parent id: %w", err)
182+
}
183+
184+
partial.URL = translator.optionalString(input.URL, "url")
185+
partial.Favorite = translator.optionalBool(input.Favorite, "favorite")
186+
partial.Rating = translator.optionalInt(input.Rating100, "rating100")
187+
partial.Details = translator.optionalString(input.Details, "details")
188+
partial.IgnoreAutoTag = translator.optionalBool(input.IgnoreAutoTag, "ignore_auto_tag")
189+
190+
partial.TagIDs, err = translator.updateIdsBulk(input.TagIds, "tag_ids")
191+
if err != nil {
192+
return nil, fmt.Errorf("converting tag ids: %w", err)
193+
}
194+
195+
ret := []*models.Studio{}
196+
197+
// Start the transaction and save the performers
198+
if err := r.withTxn(ctx, func(ctx context.Context) error {
199+
qb := r.repository.Studio
200+
201+
for _, id := range ids {
202+
local := partial
203+
local.ID = id
204+
if err := studio.ValidateModify(ctx, local, qb); err != nil {
205+
return err
206+
}
207+
208+
updated, err := qb.UpdatePartial(ctx, local)
209+
if err != nil {
210+
return err
211+
}
212+
213+
ret = append(ret, updated)
214+
}
215+
216+
return nil
217+
}); err != nil {
218+
return nil, err
219+
}
220+
221+
// execute post hooks outside of txn
222+
var newRet []*models.Studio
223+
for _, studio := range ret {
224+
r.hookExecutor.ExecutePostHooks(ctx, studio.ID, hook.StudioUpdatePost, input, translator.getFields())
225+
226+
studio, err = r.getStudio(ctx, studio.ID)
227+
if err != nil {
228+
return nil, err
229+
}
230+
231+
newRet = append(newRet, studio)
232+
}
233+
234+
return newRet, nil
235+
}
236+
166237
func (r *mutationResolver) StudioDestroy(ctx context.Context, input StudioDestroyInput) (bool, error) {
167238
id, err := strconv.Atoi(input.ID)
168239
if err != nil {

0 commit comments

Comments
 (0)