32 lines
968 B
Dart
32 lines
968 B
Dart
import 'package:flutter_android_app/data/dtos/characters_dto.dart';
|
|
import 'package:flutter_android_app/domain/models/card.dart';
|
|
|
|
import '../../domain/models/home.dart';
|
|
|
|
const _imagePlaceholder = 'https://gryazoveckij-r19.gosweb.gosuslugi.ru/netcat_files/460/2008/net_foto_muzh.jpg';
|
|
|
|
extension CharactersDataDto on CharactersDto {
|
|
HomeData toDomain() => HomeData(
|
|
data: data?.map((e) => e.toDomain()).toList(),
|
|
nextPage: meta?.pagination?.next,
|
|
);
|
|
}
|
|
|
|
extension CharacterDataDtoToModel on CharacterDataDto {
|
|
CardData toDomain() => CardData(
|
|
title: attributes?.name ?? 'UNKNOWN',
|
|
imageUrl: attributes?.image ?? _imagePlaceholder,
|
|
description: _makeDescriptionText(attributes?.born, attributes?.died),
|
|
);
|
|
}
|
|
|
|
String _makeDescriptionText(String? born, String? died) {
|
|
return born != null && died != null
|
|
? '$born - $died'
|
|
: born != null
|
|
? 'born: $born'
|
|
: died != null
|
|
? 'died: $died'
|
|
: '';
|
|
}
|