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