in process 2
This commit is contained in:
parent
63aa49af9d
commit
90808f51aa
@ -1,43 +1,23 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'characters_dto.g.dart';
|
||||
part 'titans_dto.g.dart';
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class CharactersDto {
|
||||
final List<CharactersDataDto>? results;
|
||||
class TitansDto {
|
||||
final List<TitansResultsDto>? results;
|
||||
final InfoDto? info;
|
||||
const CharactersDto({this.results, this.info});
|
||||
factory CharactersDto.fromJson(Map<String, dynamic> json) => _$CharactersDtoFromJson(json);
|
||||
const TitansDto({this.results, this.info});
|
||||
factory TitansDto.fromJson(Map<String, dynamic> json) => _$TitansDtoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class CharactersDataDto {
|
||||
class TitansResultsDto {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final String? status;
|
||||
final List<String> species;
|
||||
final String? age;
|
||||
const CharactersDataDto({this.id, this.type, this.attributes});
|
||||
factory CharactersDataDto.fromJson(Map<String, dynamic> json) =>
|
||||
final String? height;
|
||||
final List<String>? abilities;
|
||||
final String? allegiance;
|
||||
const TitansResultsDto({this.id, this.name, this.height, this.abilities, this.allegiance});
|
||||
factory TitansResultsDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$CharactersDataDtoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class InfoDto {
|
||||
final PaginationDto? pagination;
|
||||
|
||||
const InfoDto({this.pagination});
|
||||
|
||||
factory InfoDto.fromJson(Map<String, dynamic> json) => _$MetaDtoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class PaginationDto {
|
||||
final int? current;
|
||||
final int? next;
|
||||
final int? last;
|
||||
|
||||
const PaginationDto({this.current, this.next, this.last});
|
||||
|
||||
factory PaginationDto.fromJson(Map<String, dynamic> json) => _$PaginationDtoFromJson(json);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
||||
import 'package:pmd_lab/data/dtos/titans_dto.dart';
|
||||
import 'package:pmd_lab/domain/models/card.dart';
|
||||
import 'package:pmd_lab/domain/models/home.dart';
|
||||
|
||||
const _imagePlaceholder = 'https://cdn-icons-png.flaticon.com/512/4054/4054617.png';
|
||||
|
||||
extension CharacterDataDtoToModel on CharactersDataDto {
|
||||
extension CharacterDataDtoToModel on TitansResultsDto {
|
||||
CardData toDomain() => CardData(
|
||||
attributes?.name ?? 'UNKNOWN',
|
||||
name: ?.name ?? 'UNKNOWN',
|
||||
img: attributes?.image ?? _imagePlaceholder,
|
||||
description: _makeDescription(attributes?.born, attributes?.died),
|
||||
id: id,
|
||||
@ -22,7 +22,7 @@ extension CharacterDataDtoToModel on CharactersDataDto {
|
||||
}
|
||||
}
|
||||
|
||||
extension CharactersDtoToModel on CharactersDto {
|
||||
extension CharactersDtoToModel on TitansDto {
|
||||
HomeData toDomain() => HomeData(
|
||||
data: results?.map((e) => e.toDomain()).toList(),
|
||||
nextPage: info?.pagination?.next,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
||||
import 'package:pmd_lab/data/dtos/titans_dto.dart';
|
||||
import 'package:pmd_lab/data/mappes/characters_mapper.dart';
|
||||
import 'package:pmd_lab/domain/models/home.dart';
|
||||
import 'package:pmd_lab/repositories/api_interface.dart';
|
||||
@ -33,7 +33,7 @@ class PotterRepository extends ApiInterface {
|
||||
},
|
||||
);
|
||||
|
||||
final CharactersDto dto = CharactersDto.fromJson(response.data as Map<String, dynamic>);
|
||||
final TitansDto dto = TitansDto.fromJson(response.data as Map<String, dynamic>);
|
||||
final HomeData data = dto.toDomain();
|
||||
return data;
|
||||
} on DioException catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user