getStories method

Future<List<Story<StoryContent>>> getStories({
  1. String? startsWith,
  2. String? searchTerm,
  3. String? sortBy,
  4. Pagination? pagination,
  5. List<String>? byFullSlugs,
  6. List<String>? excludingFullSlugs,
  7. DateTime? publishedAfter,
  8. DateTime? publishedBefore,
  9. DateTime? firstPublishedAfter,
  10. DateTime? firstPublishedBefore,
  11. List<int>? inWorkflowStages,
  12. String? contentType,
  13. int? level,
  14. List<String>? resolveRelations,
  15. List<String>? excludingIDs,
  16. ({bool ordered, List<String> uuids})? byUUIDs,
  17. List<String>? withTags,
  18. bool? isStartpage,
  19. ResolveLinks? resolveLinks,
  20. bool resolveLinks2Levels = true,
  21. String? fromRelease,
  22. String? fallbackLanguage,
  23. String? language,
  24. List<String>? excludingFields,
  25. int? resolveAssets,
})

Retrieve multiple stories

Implementation

Future<List<Story<StoryContent>>> getStories({
  String? startsWith,
  String? searchTerm,
  String? sortBy,
  Pagination? pagination,
  List<String>? byFullSlugs,
  List<String>? excludingFullSlugs,
  DateTime? publishedAfter,
  DateTime? publishedBefore,
  DateTime? firstPublishedAfter,
  DateTime? firstPublishedBefore,
  List<int>? inWorkflowStages,
  String? contentType,
  int? level,
  List<String>? resolveRelations,
  List<String>? excludingIDs,
  ({List<String> uuids, bool ordered})? byUUIDs,
  List<String>? withTags,
  bool? isStartpage,
  ResolveLinks? resolveLinks,
  bool resolveLinks2Levels = true,
  String? fromRelease,
  String? fallbackLanguage,
  String? language,
  // TODO: filter_query
  List<String>? excludingFields,
  int? resolveAssets,
}) async {
  final json = await _getRequest(
    path: _pathStories,
    queryParameters: {
      if (_cacheVersion != null) "cv": _cacheVersion.toString(),
      if (_version != null) "version": _version.name,
      if (startsWith != null) "starts_with": startsWith,
      if (searchTerm != null) "search_term": searchTerm,
      if (sortBy != null) "sort_by": sortBy,
      if (pagination != null) ...pagination.toParameters(),
      if (byFullSlugs != null) "by_slugs": byFullSlugs.join(","),
      if (excludingFullSlugs != null) "excluding_slugs": excludingFullSlugs.join(","),
      if (publishedAfter != null) "published_at_gt": publishedAfter.format(),
      if (publishedBefore != null) "published_at_lt": publishedBefore.format(),
      if (firstPublishedAfter != null) "first_published_at_gt": firstPublishedAfter.format(),
      if (firstPublishedBefore != null) "first_published_at_lt": firstPublishedBefore.format(),
      if (inWorkflowStages != null) "in_workflow_stages": inWorkflowStages.join(","),
      if (contentType != null) "content_type": contentType,
      if (level != null) "level": level.toString(),
      if (resolveRelations != null && resolveRelations.isNotEmpty) "resolve_relations": resolveRelations.join(","),
      if (excludingIDs != null) "excluding_ids": excludingIDs.join(","),
      if (byUUIDs != null) byUUIDs.ordered ? "by_uuids_ordered" : "by_uuids": byUUIDs.uuids.join(","),
      if (withTags != null) "with_tag": withTags.join(","),
      if (isStartpage != null) "is_startpage": isStartpage ? "1" : "0",
      if (resolveLinks != null) "resolve_links": resolveLinks.name,
      if (resolveLinks2Levels) "resolve_links_level": "2",
      if (fromRelease != null) "from_release": fromRelease,
      if (fallbackLanguage != null) "fallback_lang": fallbackLanguage,
      if (language != null) "language": language,
      // TODO: filter_query
      if (excludingFields != null) "excluding_fields": excludingFields.join(","),
      if (resolveAssets != null) "resolve_assets": resolveAssets.toString(),
    },
  );
  if (resolveLinks != null) {
    _handleResolvedLinks(resolveLinks, json);
  }
  if (resolveRelations != null && resolveRelations.isNotEmpty) {
    _handleResolvedRelations(json);
  }
  final stories = List<JSONMap>.from(json["stories"]) //
      .map((e) => Story<StoryContent>.fromJson(e, _storyContentBuilder))
      .toList();
  return stories;
}