30 lines
943 B
Dart
Raw Permalink Normal View History

2022-05-11 23:41:39 -07:00
//Here is the mapper that converts the response from the endpoints to non nullable object (model)
import 'package:itasmob/app/extension.dart';
import 'package:itasmob/data/response/responses.dart';
import 'package:itasmob/domain/model/model.dart';
extension DataResponseMapper on DataResposne? {
Data toDomain(){
return Data(
this?.author?.orEmpty() ?? EMPTY,
this?.title?.orEmpty() ?? EMPTY,
this?.description?.orEmpty() ?? EMPTY,
this?.url?.orEmpty() ?? EMPTY,
this?.urlToImage?.orEmpty() ?? EMPTY,
this?.content?.orEmpty() ?? EMPTY,
this?.publishedAt?.orEmpty() ?? EMPTY,
);
}
}
extension NewsResponseMapper on NewsResponse?{
News toDomain(){
List<Data> mappedData = (this?.dataResposne.articles?.map((articles) => articles.toDomain()) ?? Iterable.empty())
.cast<Data>()
.toList();
var data = NewsData(mappedData);
return News(data);
}
}