Overview
Repositories act as the single source of truth for data operations in the TecMeli app. They implement domain repository interfaces and coordinate between remote APIs, mappers, and the domain layer.ProductRepositoryImpl
Implementation of the product catalog repository using the Mercado Libre API.Class Definition
data/repository/ProductRepositoryImpl.kt:21
Dependencies
meliApi: MeliApi- Retrofit interface for product endpoints- Uses
safeApiCallfor error handling and transformation
Methods
searchProducts
Searches for products using the Mercado Libre search endpoint.query: String- User-provided search term
Result<List<Product>> - List of products or error
Implementation: ProductRepositoryImpl.kt:31
The method uses
safeApiCall which automatically handles HTTP errors, network failures, and transforms exceptions into Result.failure.getProductDetail
Retrieves detailed information for a specific product by ID.id: String- Unique product identifier (e.g., “MCO123456”)
Result<ProductDetail> - Detailed product information or error
Implementation: ProductRepositoryImpl.kt:42
TokenRepositoryImpl
Singleton repository responsible for managing OAuth access tokens in memory.Class Definition
data/repository/TokenRepositoryImpl.kt:22
Dependencies
authApi: AuthApi- Retrofit interface for authentication endpointsapiConfig: ApiConfig- Configuration containing client credentials
Properties
Methods
getAccessToken
Returns the current access token, refreshing it if necessary.String? - Current access token or null if unavailable
Implementation: TokenRepositoryImpl.kt:39
This method uses
runBlocking to perform synchronous token refresh when called from OkHttp interceptors that require immediate token availability.refreshToken
Executes a token refresh request against the OAuth server.Result<String> - New access token or error
Implementation: TokenRepositoryImpl.kt:56
Architecture Notes
Error Handling Pattern
All repository methods use thesafeApiCall wrapper which:
- Executes the API call
- Handles network and HTTP errors
- Transforms successful responses using mapper functions
- Returns
Result<T>for clean error propagation
Dependency Injection
Both repositories are provided via Hilt dependency injection:ProductRepositoryImpl- Standard scopedTokenRepositoryImpl- Singleton scoped
Thread Safety
ProductRepositoryImpl - Thread-safe. All methods are suspend functions and don’t maintain mutable state.
Related Documentation
Remote APIs
Network layer and endpoint definitions
Mappers
DTO to domain model transformations