You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
943 B

2 years ago
  1. //Here is the mapper that converts the response from the endpoints to non nullable object (model)
  2. import 'package:itasmob/app/extension.dart';
  3. import 'package:itasmob/data/response/responses.dart';
  4. import 'package:itasmob/domain/model/model.dart';
  5. extension DataResponseMapper on DataResposne? {
  6. Data toDomain(){
  7. return Data(
  8. this?.author?.orEmpty() ?? EMPTY,
  9. this?.title?.orEmpty() ?? EMPTY,
  10. this?.description?.orEmpty() ?? EMPTY,
  11. this?.url?.orEmpty() ?? EMPTY,
  12. this?.urlToImage?.orEmpty() ?? EMPTY,
  13. this?.content?.orEmpty() ?? EMPTY,
  14. this?.publishedAt?.orEmpty() ?? EMPTY,
  15. );
  16. }
  17. }
  18. extension NewsResponseMapper on NewsResponse?{
  19. News toDomain(){
  20. List<Data> mappedData = (this?.dataResposne.articles?.map((articles) => articles.toDomain()) ?? Iterable.empty())
  21. .cast<Data>()
  22. .toList();
  23. var data = NewsData(mappedData);
  24. return News(data);
  25. }
  26. }