getStory method

Future<Story<StoryContent>> getStory({
  1. required StoryIdentifier id,
  2. ResolveLinks? resolveLinks,
  3. bool resolveLinks2Levels = true,
  4. List<String>? resolveRelations,
  5. String? fromRelease,
  6. String? language,
  7. String? fallbackLanguage,
  8. int? resolveAssets,
})

Retrieve a single story by id

Implementation

Future<Story<StoryContent>> getStory({
  required StoryIdentifier id,
  ResolveLinks? resolveLinks,
  bool resolveLinks2Levels = true,
  List<String>? resolveRelations,
  String? fromRelease,
  String? language,
  String? fallbackLanguage,
  int? resolveAssets,
}) async {
  final Map<String, String> queryParams = {
    if (_version != null) "version": _version.name,
    if (resolveLinks != null) "resolve_links": resolveLinks.name,
    if (resolveLinks2Levels) "resolve_links_level": "2",
    if (resolveRelations != null && resolveRelations.isNotEmpty) "resolve_relations": resolveRelations.join(","),
    if (fromRelease != null) "from_release": fromRelease,
    if (_cacheVersion != null) "cv": _cacheVersion.toString(),
    if (language != null) "language": language,
    if (fallbackLanguage != null) "fallback_lang": fallbackLanguage,
    if (resolveAssets != null)
      "resolve_assets": resolveAssets.toString(), // TODO: Figure out how resolve_assets works, docs doesnt say...
  };
  final json = await switch (id) {
    StoryIdentifierID(:final id) => _getRequest(
        path: "$_pathStories/$id",
        queryParameters: queryParams,
      ),
    StoryIdentifierUUID(:final uuid) => _getRequest(
        path: "$_pathStories/$uuid",
        queryParameters: {
          ...queryParams,
          "find_by": "uuid",
        },
      ),
    StoryIdentifierFullSlug(:final slug) => _getRequest(
        path: "$_pathStories/$slug",
        queryParameters: queryParams,
      ),
  };
  if (resolveLinks != null) {
    _handleResolvedLinks(resolveLinks, json);
  }
  if (resolveRelations != null && resolveRelations.isNotEmpty) {
    _handleResolvedRelations(json);
  }
  final story = Story<StoryContent>.fromJson(json["story"], _storyContentBuilder);
  return story;
}