Overview
TheArticleRepository defines the contract for accessing article data in the Space Flight News app. It provides methods to fetch articles with optional filtering and retrieve individual article details.
Package: com.bsvillarraga.spaceflightnews.domain.repository
Implementation: ArticleRepositoryImpl
Interface
Methods
getArticles
Retrieves a list of articles from the API with optional search filtering.Optional search query to filter articles by title, summary, or content
A Resource wrapper containing either:
Resource.Success<List<Article>>- List of articles matching the queryResource.Error- Error information including error code and message
Example Usage
getArticleById
Retrieves detailed information for a specific article by its unique identifier.The unique identifier of the article to retrieve
A Resource wrapper containing either:
Resource.Success<ArticleDetail>- Complete article details including authors, summary, and metadataResource.Error- Error information if the article is not found or request fails
Example Usage
Implementation
ArticleRepositoryImpl
Package:com.bsvillarraga.spaceflightnews.data.repository
Source: ArticleRepositoryImpl.kt
The implementation uses:
- ArticlesApiClient - Retrofit client for API calls
- ApiHelper - Safe API call handling with error management
- PaginationManager - Manages pagination state and offsets
Key Features
- Coroutine Support: All methods are suspend functions running on
Dispatchers.IO - Error Handling: Wraps API responses in
Resourcefor consistent error handling - Pagination: Automatically manages pagination using
PaginationManager - Data Mapping: Converts DTOs to domain models using mapper functions
Dependency Injection
The repository is provided through Hilt dependency injection inNetworkModule:
Related
- ArticlesApiClient - HTTP client interface
- Data Models - DTO and domain model definitions
- Resource Class - Result wrapper for success/error states