diff --git a/lib/data/dtos/pokemon_dto.dart b/lib/data/dtos/pokemon_dto.dart index 021402e..de8e84e 100644 --- a/lib/data/dtos/pokemon_dto.dart +++ b/lib/data/dtos/pokemon_dto.dart @@ -30,4 +30,37 @@ class PokemonDataDto { }); factory PokemonDataDto.fromJson(Map json) => _$PokemonDataDtoFromJson(json); +} + +@JsonSerializable(createToJson: false) +class PokemonDetailsDto { + final int? height; + final int? weight; + final List? abilities; + + const PokemonDetailsDto({ + this.height, + this.weight, + this.abilities, + }); + + factory PokemonDetailsDto.fromJson(Map json) => _$PokemonDetailsDtoFromJson(json); +} + +@JsonSerializable(createToJson: false) +class AbilityDto { + final AbilityDetailDto? ability; + + const AbilityDto({this.ability}); + + factory AbilityDto.fromJson(Map json) => _$AbilityDtoFromJson(json); +} + +@JsonSerializable(createToJson: false) +class AbilityDetailDto { + final String? name; + + const AbilityDetailDto({this.name}); + + factory AbilityDetailDto.fromJson(Map json) => _$AbilityDetailDtoFromJson(json); } \ No newline at end of file diff --git a/lib/data/dtos/pokemon_dto.g.dart b/lib/data/dtos/pokemon_dto.g.dart deleted file mode 100644 index 1f8787d..0000000 --- a/lib/data/dtos/pokemon_dto.g.dart +++ /dev/null @@ -1,22 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'pokemon_dto.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -PokemonDto _$PokemonDtoFromJson(Map json) => PokemonDto( - results: (json['results'] as List?) - ?.map((e) => PokemonDataDto.fromJson(e as Map)) - .toList(), - count: (json['count'] as num?)?.toInt(), - next: json['next'] as String?, - previous: json['previous'] as String?, - ); - -PokemonDataDto _$PokemonDataDtoFromJson(Map json) => - PokemonDataDto( - name: json['name'] as String?, - url: json['url'] as String?, - ); diff --git a/lib/data/mappers/pokemon_mapper.dart b/lib/data/mappers/pokemon_mapper.dart index 177be9b..5b74a9b 100644 --- a/lib/data/mappers/pokemon_mapper.dart +++ b/lib/data/mappers/pokemon_mapper.dart @@ -24,4 +24,11 @@ extension PokemonDataDtoToModel on PokemonDataDto { id: id, ); } +} + +extension PokemonDetailsDtoToModel on PokemonDetailsDto { + String toDescriptionText() { + final abilitiesText = abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN'; + return 'Height: ${height ?? 'UNKNOWN'} cm, Weight: ${weight ?? 'UNKNOWN'} kg, Abilities: $abilitiesText'; + } } \ No newline at end of file