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';
|
|
|
|
|
2024-10-29 14:54:56 +04:00
|
|
|
extension PokemonDtoToModel on PokemonDto {
|
2024-10-17 00:37:52 +04:00
|
|
|
HomeData toDomain() => HomeData(
|
2024-10-29 14:36:44 +04:00
|
|
|
data: results?.map((e) => e.toDomain()).toList(),
|
2024-10-29 14:54:56 +04:00
|
|
|
nextPage: next != null ? int.tryParse(next!.split('=')[1].split('&')[0]) : null,
|
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-29 14:54:56 +04:00
|
|
|
extension PokemonDataDtoToModel on PokemonDataDto {
|
2024-11-17 21:35:47 +04:00
|
|
|
CardData toDomain() => CardData(
|
|
|
|
name ?? 'UNKNOWN',
|
|
|
|
imageUrl: imageUrl ?? _imagePlaceholder,
|
2024-11-18 13:20:53 +04:00
|
|
|
descriptionText: 'Height: ${height ?? 'UNKNOWN'} cm, Weight: ${weight ?? 'UNKNOWN'} g, Abilities: ${abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN'}',
|
2024-11-18 16:28:59 +04:00
|
|
|
// imageUrl: attributes?.sprites?.front_default ?? _imagePlaceholder,
|
|
|
|
// descriptionText: 'Height: ${attributes?.height ?? 'UNKNOWN'} cm, Weight: ${attributes?.weight ?? 'UNKNOWN'} g, Abilities: ${attributes?.abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN'}',
|
2024-11-17 21:35:47 +04:00
|
|
|
id: url?.split('/')[6] ?? 'UNKNOWN',
|
|
|
|
);
|
2024-10-17 00:37:52 +04:00
|
|
|
}
|