Skip to content

Commit 6197e4d

Browse files
committed
Use paginated api when fetching log entries
1 parent 984df49 commit 6197e4d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/providers/nutrition.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class NutritionPlansProvider with ChangeNotifier {
103103

104104
/// Fetches and sets all plans fully, i.e. with all corresponding child objects
105105
Future<void> fetchAndSetAllPlansFull() async {
106-
final data = await baseProvider.fetch(baseProvider.makeUrl(_nutritionalPlansPath));
107-
for (final entry in data['results']) {
106+
final data = await baseProvider.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath));
107+
for (final entry in data) {
108108
await fetchAndSetPlanFull(entry['id']);
109109
}
110110
}
@@ -411,16 +411,15 @@ class NutritionPlansProvider with ChangeNotifier {
411411

412412
/// Load nutrition diary entries for plan
413413
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
414-
// TODO(x): update fetch to that it can use the pagination
415-
final data = await baseProvider.fetch(
414+
final data = await baseProvider.fetchPaginated(
416415
baseProvider.makeUrl(
417416
_nutritionDiaryPath,
418-
query: {'plan': plan.id.toString(), 'limit': '1000'},
417+
query: {'plan': plan.id.toString(), 'limit': '999'},
419418
),
420419
);
421420

422421
plan.logs = [];
423-
for (final logData in data['results']) {
422+
for (final logData in data) {
424423
final log = Log.fromJson(logData);
425424
final ingredient = await fetchIngredient(log.ingredientId);
426425
log.ingredientObj = ingredient;

0 commit comments

Comments
 (0)