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';
|
|
|
|
|
2024-10-16 11:29:51 +04:00
|
|
|
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';
|
|
|
|
|
2024-10-16 11:29:51 +04:00
|
|
|
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'
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
}
|