Mobiles_programming/lib/data/mappers/games_mapper.dart

28 lines
1.0 KiB
Dart

import 'package:mobiles_labs_5th_semester/data/dto/games_dto.dart';
import 'package:mobiles_labs_5th_semester/domain/models/game.dart';
import 'package:mobiles_labs_5th_semester/domain/models/page_of_games_home.dart';
extension GamesDtoToModel on GamesDto {
PageOfGames toDomain() => PageOfGames(
data: data?.map((e) => e.toDomain()).toList(),
nextPage: next);
}
extension GameDtoToModel on GameDto {
GameData toDomain() {
// удаление HTML-тегов из описания
String cleanedDescription = description ?? '';
if (cleanedDescription.isNotEmpty) {
cleanedDescription =
cleanedDescription.replaceAll(RegExp(r'<[^>]*>'), '');
}
// return GameData(name: name ?? 'Неизвестная игра', price: 100, image: image?.originalUrl, description: cleanedDescription);
return GameData(
id: id,
name: name ?? 'Неизвестная игра',
date: DateTime.parse(date ?? '2000-01-01'),
image: image,
description: cleanedDescription);
}
}