2024-09-30 18:24:51 +04:00
|
|
|
import 'package:pmu_labworks/data/dtos/characters_dto.dart';
|
|
|
|
import 'package:pmu_labworks/domain/models/comment.dart';
|
2024-09-30 22:15:55 +04:00
|
|
|
import 'package:pmu_labworks/domain/models/home.dart';
|
2024-09-30 18:24:51 +04:00
|
|
|
import 'package:pmu_labworks/domain/models/user.dart';
|
|
|
|
|
2024-09-30 22:15:55 +04:00
|
|
|
extension CharactersDtoToModel on CharactersDto {
|
|
|
|
HomeData toDomain() => HomeData(
|
|
|
|
data: data?.map((e) => e.toDomain()).toList(),
|
|
|
|
nextPage: meta?.pagination?.next,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-09-30 18:24:51 +04:00
|
|
|
extension CharacterDataDtoToModel on CharacterDataDto {
|
2024-09-30 22:15:55 +04:00
|
|
|
CommentData toDomain() => CommentData(
|
2024-09-30 18:24:51 +04:00
|
|
|
title: type ?? 'UNKNOWN',
|
|
|
|
text: _makeDescriptionText(attributes?.born, attributes?.died),
|
2024-09-30 22:15:55 +04:00
|
|
|
user: UserData(
|
2024-09-30 18:24:51 +04:00
|
|
|
nickname: attributes?.name ?? 'Noname',
|
|
|
|
avatarUrl: attributes?.image),
|
|
|
|
);
|
|
|
|
|
|
|
|
String _makeDescriptionText(String? born, String? died) {
|
|
|
|
if (born != null && died != null) {
|
|
|
|
return '$born - $died';
|
|
|
|
} else if (born != null) {
|
|
|
|
return 'born: $born';
|
|
|
|
} else if (died != null) {
|
|
|
|
return 'died: $died';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|