PIbd-32_Chubykina_P.P._mobilki/lib/data/mappers/characters_mapper.dart

32 lines
975 B
Dart
Raw Normal View History

2024-10-07 17:59:30 +04:00
import 'package:mobilki_lab1/data/dtos/characters_dto.dart';
import 'package:mobilki_lab1/domain/models/card.dart';
import '../../domain/models/home.dart';
2024-10-07 17:59:30 +04:00
const _imagePlaceholder =
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
extension CharactersDtoToModel on CharactersDto {
HomeData toDomain() => HomeData(
data: data?.map((e) => e.toDomain()).toList(),
nextPage: meta?.pagination?.next,
);
}
2024-10-07 17:59:30 +04:00
extension CharacterDataDtoToModel on CharacterDataDto {
CardData toDomain() => CardData(
attributes?.name ?? 'UNKNOWN',
imageUrl: attributes?.image ?? _imagePlaceholder,
descriptionText: _makeDescriptionText(attributes?.born, attributes?.died),
);
String _makeDescriptionText(String? born, String? died) {
return born != null && died != null
? '$born - $died'
: born != null
? 'born: $born'
: died != null
? 'died: $died'
: '';
}
}