Files
neomovies-mobile/lib/data/models/favorite.dart

43 lines
1.2 KiB
Dart
Raw Normal View History

2025-07-13 14:01:29 +03:00
import 'package:flutter_dotenv/flutter_dotenv.dart';
class Favorite {
2025-10-02 19:54:32 +00:00
final String id; // MongoDB ObjectID as string
2025-07-13 14:01:29 +03:00
final String mediaId;
2025-10-02 19:54:32 +00:00
final String mediaType; // "movie" or "tv"
2025-07-13 14:01:29 +03:00
final String title;
final String posterPath;
2025-10-02 19:54:32 +00:00
final DateTime? createdAt;
2025-07-13 14:01:29 +03:00
Favorite({
required this.id,
required this.mediaId,
required this.mediaType,
required this.title,
required this.posterPath,
2025-10-02 19:54:32 +00:00
this.createdAt,
2025-07-13 14:01:29 +03:00
});
factory Favorite.fromJson(Map<String, dynamic> json) {
return Favorite(
2025-10-02 19:54:32 +00:00
id: json['id'] as String? ?? '',
2025-07-13 14:01:29 +03:00
mediaId: json['mediaId'] as String? ?? '',
2025-10-02 19:54:32 +00:00
mediaType: json['mediaType'] as String? ?? 'movie',
2025-07-13 14:01:29 +03:00
title: json['title'] as String? ?? '',
posterPath: json['posterPath'] as String? ?? '',
2025-10-02 19:54:32 +00:00
createdAt: json['createdAt'] != null
? DateTime.tryParse(json['createdAt'] as String)
: null,
2025-07-13 14:01:29 +03:00
);
}
String get fullPosterUrl {
if (posterPath.isEmpty) {
2025-10-02 21:40:20 +00:00
return 'https://via.placeholder.com/500x750.png?text=No+Poster';
2025-07-13 14:01:29 +03:00
}
2025-10-02 21:40:20 +00:00
// TMDB CDN base URL
const tmdbBaseUrl = 'https://image.tmdb.org/t/p';
2025-07-13 14:01:29 +03:00
final cleanPath = posterPath.startsWith('/') ? posterPath.substring(1) : posterPath;
2025-10-02 21:40:20 +00:00
return '$tmdbBaseUrl/w500/$cleanPath';
2025-07-13 14:01:29 +03:00
}
}