31 lines
981 B
Dart
31 lines
981 B
Dart
import 'package:pmd_lab/data/dtos/characters_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 {
|
|
CardData toDomain() => CardData(
|
|
attributes?.name ?? 'UNKNOWN',
|
|
img: attributes?.image ?? _imagePlaceholder,
|
|
description: _makeDescription(attributes?.born, attributes?.died),
|
|
id: id,
|
|
);
|
|
String _makeDescription(String? born, String? died) {
|
|
return born != null && died != null
|
|
? '$born - $died'
|
|
: born != null
|
|
? 'born: $born'
|
|
: died != null
|
|
? 'died: $died'
|
|
: '';
|
|
}
|
|
}
|
|
|
|
extension CharactersDtoToModel on CharactersDto {
|
|
HomeData toDomain() => HomeData(
|
|
data: data?.map((e) => e.toDomain()).toList(),
|
|
nextPage: meta?.pagination?.next,
|
|
);
|
|
}
|