PIbd-31_MasenkinMS_PMU/lib/data/mappers/characters_mapper.dart
2024-09-30 18:24:51 +04:00

26 lines
800 B
Dart

import 'package:pmu_labworks/data/dtos/characters_dto.dart';
import 'package:pmu_labworks/domain/models/comment.dart';
import 'package:pmu_labworks/domain/models/user.dart';
extension CharacterDataDtoToModel on CharacterDataDto {
CommentModel toDomain() => CommentModel(
title: type ?? 'UNKNOWN',
text: _makeDescriptionText(attributes?.born, attributes?.died),
user: UserModel(
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 '';
}
}
}