Skip to content

Commit 5d61539

Browse files
committed
fix(api): update data operation registry to use new limit services
This change updates the DataOperationRegistry to correctly call the new methods on the UserPreferenceLimitService. The custom creator and updater for the 'interest' model now use the correct named arguments (user, interest) when calling checkInterestLimits, resolving the compile-time errors. A custom updater has been added for 'user_content_preferences' to call the new checkUserContentPreferencesLimits method, ensuring that limits for followed items and saved headlines are now correctly enforced before any update.
1 parent 10ab766 commit 5d61539

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

lib/src/registry/data_operation_registry.dart

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,20 @@ class DataOperationRegistry {
175175
sort: s,
176176
pagination: p,
177177
),
178-
'interest': (c, uid, f, s, p) => c.read<DataRepository<Interest>>().readAll(
179-
userId: uid,
180-
filter: f,
181-
sort: s,
182-
pagination: p,
183-
),
178+
'interest': (c, uid, f, s, p) =>
179+
c.read<DataRepository<Interest>>().readAll(
180+
userId: uid,
181+
filter: f,
182+
sort: s,
183+
pagination: p,
184+
),
184185
'in_app_notification': (c, uid, f, s, p) =>
185186
c.read<DataRepository<InAppNotification>>().readAll(
186-
userId: uid,
187-
filter: f,
188-
sort: s,
189-
pagination: p,
190-
),
187+
userId: uid,
188+
filter: f,
189+
sort: s,
190+
pagination: p,
191+
),
191192
});
192193

193194
// --- Register Item Creators ---
@@ -290,15 +291,15 @@ class DataOperationRegistry {
290291

291292
// 2. Check limits before creating.
292293
await context.read<UserPreferenceLimitService>().checkInterestLimits(
293-
authenticatedUser,
294-
interestToCreate,
295-
existingInterests: preferences.interests,
296-
);
294+
user: authenticatedUser,
295+
interest: interestToCreate,
296+
existingInterests: preferences.interests,
297+
);
297298

298299
// 3. Proceed with creation.
299300
return context.read<DataRepository<Interest>>().create(
300-
item: interestToCreate,
301-
);
301+
item: interestToCreate,
302+
);
302303
},
303304
});
304305

@@ -413,9 +414,27 @@ class DataOperationRegistry {
413414
'user_app_settings': (c, id, item, uid) => c
414415
.read<DataRepository<UserAppSettings>>()
415416
.update(id: id, item: item as UserAppSettings, userId: uid),
416-
'user_content_preferences': (c, id, item, uid) => c
417-
.read<DataRepository<UserContentPreferences>>()
418-
.update(id: id, item: item as UserContentPreferences, userId: uid),
417+
'user_content_preferences': (context, id, item, uid) async {
418+
_log.info(
419+
'Executing custom updater for user_content_preferences ID: $id.',
420+
);
421+
final authenticatedUser = context.read<User>();
422+
final preferencesToUpdate = item as UserContentPreferences;
423+
424+
// 1. Check limits before updating.
425+
await context
426+
.read<UserPreferenceLimitService>()
427+
.checkUserContentPreferencesLimits(
428+
user: authenticatedUser,
429+
updatedPreferences: preferencesToUpdate,
430+
);
431+
432+
// 2. Proceed with update.
433+
return context.read<DataRepository<UserContentPreferences>>().update(
434+
id: id,
435+
item: preferencesToUpdate,
436+
);
437+
},
419438
'remote_config': (c, id, item, uid) => c
420439
.read<DataRepository<RemoteConfig>>()
421440
.update(id: id, item: item as RemoteConfig, userId: uid),
@@ -430,18 +449,22 @@ class DataOperationRegistry {
430449
.read(id: authenticatedUser.id);
431450

432451
// Exclude the interest being updated from the list for limit checking.
433-
final otherInterests =
434-
preferences.interests.where((i) => i.id != id).toList();
452+
final otherInterests = preferences.interests
453+
.where((i) => i.id != id)
454+
.toList();
435455

436456
// 2. Check limits before updating.
437457
await context.read<UserPreferenceLimitService>().checkInterestLimits(
438-
authenticatedUser,
439-
interestToUpdate,
440-
existingInterests: otherInterests,
441-
);
458+
user: authenticatedUser,
459+
interest: interestToUpdate,
460+
existingInterests: otherInterests,
461+
);
442462

443463
// 3. Proceed with update.
444-
return context.read<DataRepository<Interest>>().update(id: id, item: interestToUpdate);
464+
return context.read<DataRepository<Interest>>().update(
465+
id: id,
466+
item: interestToUpdate,
467+
);
445468
},
446469
});
447470

0 commit comments

Comments
 (0)