2024-10-14 21:25:43 +04:00
|
|
|
import 'package:mobilki_lab1/data/dtos/pokemon_dto.dart';
|
|
|
|
import 'package:mobilki_lab1/domain/models/card.dart';
|
2024-10-17 00:37:52 +04:00
|
|
|
import 'package:mobilki_lab1/domain/models/home.dart';
|
2024-10-14 21:25:43 +04:00
|
|
|
|
|
|
|
const _imagePlaceholder =
|
|
|
|
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
|
|
|
|
|
|
|
|
extension PokemonDtoToModel on PokemonDto {
|
2024-10-17 00:37:52 +04:00
|
|
|
HomeData toDomain() => HomeData(
|
2024-10-18 21:36:44 +04:00
|
|
|
data: data?.map((e) => e.toDomain()).toList(),
|
|
|
|
nextPage: meta?.pagination?.next,
|
2024-10-17 00:37:52 +04:00
|
|
|
);
|
2024-10-18 21:36:44 +04:00
|
|
|
}
|
2024-10-14 21:25:43 +04:00
|
|
|
|
2024-10-18 21:36:44 +04:00
|
|
|
extension PokemonDataDtoToModel on PokemonDataDto {
|
|
|
|
CardData toDomain() => CardData(
|
|
|
|
attributes?.name ?? 'UNKNOWN',
|
|
|
|
imageUrl: attributes?.image ?? _imagePlaceholder,
|
|
|
|
descriptionText: _makeDescriptionText(attributes?.height, attributes?.weight),
|
|
|
|
id: id,
|
2024-10-17 00:37:52 +04:00
|
|
|
);
|
|
|
|
|
2024-10-18 21:36:44 +04:00
|
|
|
String _makeDescriptionText(String? height, String? weight) {
|
|
|
|
return height != null && weight != null
|
|
|
|
? 'Height: $height, Weight: $weight'
|
|
|
|
: height != null
|
|
|
|
? 'Height: $height'
|
|
|
|
: weight != null
|
|
|
|
? 'Weight: $weight'
|
|
|
|
: '';
|
2024-10-14 21:25:43 +04:00
|
|
|
}
|
2024-10-17 00:37:52 +04:00
|
|
|
}
|