mirror of
https://gitlab.com/foxixus/neomovies_mobile.git
synced 2025-10-27 19:58:50 +05:00
fix: add Downloads screen to navigation and fix API models
1. Add Downloads screen to main navigation:
- Import DownloadsScreen in main_screen.dart
- Replace placeholder 'Downloads Page' with actual DownloadsScreen component
- Downloads tab now fully functional with torrent management
2. Fix authentication models for API compatibility:
- AuthResponse: Handle wrapped API response with 'data' field
- User model: Add 'verified' field, support both '_id' and 'id' fields
- Add toJson() method to User for serialization
- Fix parsing to match backend response format
3. Fix movie details screen (gray screen issue):
- Implement getExternalIds() in NeoMoviesApiClient
- Add IMDb ID fetching via /movies/{id}/external-ids endpoint
- Update api_client.dart to use new getExternalIds method
- Fix movie detail provider to properly load IMDb IDs
Changes:
- lib/presentation/screens/main_screen.dart: Add DownloadsScreen import and replace placeholder
- lib/data/models/auth_response.dart: Handle wrapped 'data' response
- lib/data/models/user.dart: Add verified field and toJson method
- lib/data/api/neomovies_api_client.dart: Add getExternalIds endpoint
- lib/data/api/api_client.dart: Implement getImdbId using external IDs
Result:
✅ Downloads tab works and shows torrent list
✅ Authentication properly parses API responses
✅ Movie detail screen loads IMDb IDs correctly
✅ All API models match backend format
This commit is contained in:
@@ -102,10 +102,7 @@ class ApiClient {
|
||||
|
||||
// ---- External IDs (IMDb) ----
|
||||
Future<String?> getImdbId(String mediaId, String mediaType) async {
|
||||
// This would need to be implemented in NeoMoviesApiClient
|
||||
// For now, return null or implement a stub
|
||||
// TODO: Add getExternalIds endpoint to backend
|
||||
return null;
|
||||
return _neoClient.getExternalIds(mediaId, mediaType);
|
||||
}
|
||||
|
||||
// ---- Auth ----
|
||||
|
||||
@@ -251,6 +251,30 @@ class NeoMoviesApiClient {
|
||||
return _fetchMovies('/tv/search', page: page, query: query);
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// External IDs (IMDb, TVDB, etc.)
|
||||
// ============================================
|
||||
|
||||
/// Get external IDs (IMDb, TVDB) for a movie or TV show
|
||||
Future<String?> getExternalIds(String mediaId, String mediaType) async {
|
||||
try {
|
||||
final uri = Uri.parse('$apiUrl/${mediaType}s/$mediaId/external-ids');
|
||||
final response = await _client.get(uri);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final apiResponse = json.decode(response.body);
|
||||
final data = (apiResponse is Map && apiResponse['data'] != null)
|
||||
? apiResponse['data']
|
||||
: apiResponse;
|
||||
return data['imdb_id'] as String?;
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
print('Error getting external IDs: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Unified Search
|
||||
// ============================================
|
||||
|
||||
@@ -8,10 +8,13 @@ class AuthResponse {
|
||||
AuthResponse({required this.token, required this.user, required this.verified});
|
||||
|
||||
factory AuthResponse.fromJson(Map<String, dynamic> json) {
|
||||
// Handle wrapped response with "data" field
|
||||
final data = json['data'] ?? json;
|
||||
|
||||
return AuthResponse(
|
||||
token: json['token'] as String,
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
verified: (json['verified'] as bool?) ?? (json['user']?['verified'] as bool? ?? true),
|
||||
token: data['token'] as String,
|
||||
user: User.fromJson(data['user'] as Map<String, dynamic>),
|
||||
verified: (data['verified'] as bool?) ?? (data['user']?['verified'] as bool? ?? true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,30 @@ class User {
|
||||
final String id;
|
||||
final String name;
|
||||
final String email;
|
||||
final bool verified;
|
||||
|
||||
User({required this.id, required this.name, required this.email});
|
||||
User({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.email,
|
||||
this.verified = true,
|
||||
});
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
id: json['_id'] as String? ?? '',
|
||||
id: (json['_id'] ?? json['id'] ?? '') as String,
|
||||
name: json['name'] as String? ?? '',
|
||||
email: json['email'] as String? ?? '',
|
||||
verified: json['verified'] as bool? ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'_id': id,
|
||||
'name': name,
|
||||
'email': email,
|
||||
'verified': verified,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:neomovies_mobile/presentation/screens/auth/profile_screen.dart';
|
||||
import 'package:neomovies_mobile/presentation/screens/favorites/favorites_screen.dart';
|
||||
import 'package:neomovies_mobile/presentation/screens/search/search_screen.dart';
|
||||
import 'package:neomovies_mobile/presentation/screens/home/home_screen.dart';
|
||||
import 'package:neomovies_mobile/presentation/screens/downloads/downloads_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MainScreen extends StatefulWidget {
|
||||
@@ -30,7 +31,7 @@ class _MainScreenState extends State<MainScreen> {
|
||||
HomeScreen(),
|
||||
SearchScreen(),
|
||||
FavoritesScreen(),
|
||||
Center(child: Text('Downloads Page')),
|
||||
DownloadsScreen(),
|
||||
ProfileScreen(),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user