Skip to content

[DN] Implement API to fetch single story #602

@ataulm

Description

@ataulm

We're relying on a cache in StoriesRepository to get the data required to display a Designer News story:

class GetStoryUseCase @Inject constructor(private val storiesRepository: StoriesRepository) {

    operator fun invoke(id: Long): Result<Story> {
        val result = storiesRepository.getStory(id)
        return if (result is Result.Success) {
            Result.Success(result.data.toStory())
        } else {
            Result.Error(IllegalStateException("Story $id not cached"))
        }
    }
}

The cache is populated when retrieving a bundle of stories from the API StoriesRepository.loadStories(page: Int).

If the story is not present in the cache, then we'll return an error.


This blocks #436 because it's not possible to populate this cache from the scraped search API because we only get ID and title. The two proposed solutions in that ticket

  • chain the search call onto fetching the full data for each of the stories
  • (I started working on this one)
    introduce a new StorySearchResult PlaidItem (which only needs ID, title) and defer the fetch until opening the details

each depend on there being an API for fetching an individual story.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions