2024-09-22 20:35:55 +04:00
|
|
|
import '../../domain/models/card.dart';
|
|
|
|
import '../../domain/models/home.dart';
|
|
|
|
import '../dtos/characters_dto.dart';
|
|
|
|
|
|
|
|
extension CharactersDtoToModel on CharactersDto {
|
|
|
|
HomeData toDomain() => HomeData(
|
|
|
|
data: data?.map((e) => e.toDomain()).toList(),
|
|
|
|
nextPage: meta?.pagination?.next,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
extension CharacterDataDtoToModel on CharacterDataDto {
|
|
|
|
CardData toDomain() => CardData(
|
|
|
|
attributes?.name ?? 'UNKNOWN',
|
2024-09-22 22:30:44 +04:00
|
|
|
image: attributes?.image ??
|
|
|
|
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png',
|
|
|
|
descriptionText: _makeDescriptionText(attributes?.nationality, attributes?.species),
|
2024-09-22 20:35:55 +04:00
|
|
|
id: id,
|
|
|
|
);
|
|
|
|
|
2024-09-22 22:30:44 +04:00
|
|
|
String _makeDescriptionText(String? nationality, String? species) {
|
|
|
|
return nationality != null && species != null
|
|
|
|
? 'Nationality - $nationality \nSpecies - $species'
|
|
|
|
: nationality != null
|
|
|
|
? 'Nationality - $nationality'
|
|
|
|
: species != null
|
|
|
|
? 'Species - $species'
|
2024-09-22 20:35:55 +04:00
|
|
|
: '';
|
|
|
|
}
|
|
|
|
}
|