Created
February 1, 2022 16:35
-
-
Save AbedElazizShe/b5bd22a4b230d76cb033109b2e674b2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:data/data.dart'; | |
import 'package:injectable/injectable.dart'; | |
import 'package:remote/src/api/articles_service.dart'; | |
import 'package:remote/src/mapper/articles_entity_mapper.dart'; | |
import 'package:remote/src/models/article/article_model.dart'; | |
import 'package:remote/src/models/article/articles_response_model.dart'; | |
@Injectable(as: ArticlesRemoteRepository) | |
class ArticlesRemoteRepositoryImpl extends ArticlesRemoteRepository { | |
ArticlesRemoteRepositoryImpl({ | |
required this.articlesService, | |
required this.articlesEntityMapper, | |
}); | |
final ArticlesService articlesService; | |
final ArticlesEntityMapper articlesEntityMapper; | |
@override | |
Future<List<ArticlesEntity>> getMostEmailedArticles() async { | |
final ArticlesResponseModel articlesResponseModel = | |
await articlesService.getMostEmailedArticles(); | |
return _getMappedArticles(articlesResponseModel); | |
} | |
@override | |
Future<List<ArticlesEntity>> getMostSharedArticles() async { | |
final ArticlesResponseModel articlesResponseModel = | |
await articlesService.getMostSharedArticles(); | |
return _getMappedArticles(articlesResponseModel); | |
} | |
@override | |
Future<List<ArticlesEntity>> getMostViewedArticles() async { | |
final ArticlesResponseModel articlesResponseModel = | |
await articlesService.getMostViewedArticles(); | |
return _getMappedArticles(articlesResponseModel); | |
} | |
List<ArticlesEntity> _getMappedArticles( | |
ArticlesResponseModel articlesResponseModel) => | |
articlesResponseModel.results | |
.map((ArticleModel model) => articlesEntityMapper.mapFromModel(model)) | |
.toList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment