2024-11-13 21:23:25 +03:00
|
|
|
import 'package:pmd_labs/data/dtos/movies_dto.dart';
|
|
|
|
import 'package:pmd_labs/domain/models/carddata.dart';
|
|
|
|
import 'package:pmd_labs/presentation/home_page/home_page.dart';
|
|
|
|
|
2024-11-14 16:44:44 +03:00
|
|
|
const _imagePlaceholder =
|
|
|
|
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
|
|
|
|
|
2024-11-13 21:23:25 +03:00
|
|
|
extension MovieDataDtoMapper on MovieDataDto {
|
|
|
|
CardData toDomain() => CardData(
|
2024-11-14 16:44:44 +03:00
|
|
|
name ?? 'UNKNOWN',
|
|
|
|
imageUrl: poster?.url ?? _imagePlaceholder,
|
|
|
|
id: id?.toString() ?? '0',
|
|
|
|
descriptionText: description ?? 'Нет описания',
|
|
|
|
year: year,
|
|
|
|
genres: genres?.map((genre) => genre.name ?? 'UNKNOWN').toList() ?? [],
|
|
|
|
countries: countries?.map((country) => country.name ?? 'UNKNOWN').toList() ?? [],
|
2024-11-13 21:23:25 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
extension MoviesDtoToModel on MoviesDto {
|
|
|
|
HomeData toDomain() => HomeData(
|
2024-11-14 16:44:44 +03:00
|
|
|
data: docs?.map((e) => e.toDomain()).toList(),
|
2024-11-13 21:23:25 +03:00
|
|
|
nextPage: (pagination?.hasNextPage ?? false)
|
|
|
|
? ((pagination?.currentPage ?? 0) + 1)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
}
|