mirror of
https://gitlab.com/foxixus/neomovies_mobile.git
synced 2025-10-27 19:58:50 +05:00
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
142 lines
4.1 KiB
Dart
142 lines
4.1 KiB
Dart
import 'package:http/http.dart' as http;
|
|
import 'package:neomovies_mobile/data/models/movie.dart';
|
|
import 'package:neomovies_mobile/data/models/favorite.dart';
|
|
import 'package:neomovies_mobile/data/models/reaction.dart';
|
|
import 'package:neomovies_mobile/data/models/auth_response.dart';
|
|
import 'package:neomovies_mobile/data/models/user.dart';
|
|
import 'package:neomovies_mobile/data/api/neomovies_api_client.dart'; // новый клиент
|
|
import 'package:neomovies_mobile/data/exceptions/auth_exceptions.dart';
|
|
|
|
class ApiClient {
|
|
final NeoMoviesApiClient _neoClient;
|
|
|
|
ApiClient(http.Client client)
|
|
: _neoClient = NeoMoviesApiClient(client);
|
|
|
|
// ---- Movies ----
|
|
Future<List<Movie>> getPopularMovies({int page = 1}) {
|
|
return _neoClient.getPopularMovies(page: page);
|
|
}
|
|
|
|
Future<List<Movie>> getTopRatedMovies({int page = 1}) {
|
|
return _neoClient.getTopRatedMovies(page: page);
|
|
}
|
|
|
|
Future<List<Movie>> getUpcomingMovies({int page = 1}) {
|
|
return _neoClient.getUpcomingMovies(page: page);
|
|
}
|
|
|
|
Future<Movie> getMovieById(String id) {
|
|
return _neoClient.getMovieById(id);
|
|
}
|
|
|
|
Future<Movie> getTvById(String id) {
|
|
return _neoClient.getTvShowById(id);
|
|
}
|
|
|
|
// ---- Search ----
|
|
Future<List<Movie>> searchMovies(String query, {int page = 1}) {
|
|
return _neoClient.search(query, page: page);
|
|
}
|
|
|
|
// ---- Favorites ----
|
|
Future<List<Favorite>> getFavorites() {
|
|
return _neoClient.getFavorites();
|
|
}
|
|
|
|
Future<void> addFavorite(
|
|
String mediaId,
|
|
String mediaType,
|
|
String title,
|
|
String posterPath,
|
|
) {
|
|
return _neoClient.addFavorite(
|
|
mediaId: mediaId,
|
|
mediaType: mediaType,
|
|
title: title,
|
|
posterPath: posterPath,
|
|
);
|
|
}
|
|
|
|
Future<void> removeFavorite(String mediaId, {String mediaType = 'movie'}) {
|
|
return _neoClient.removeFavorite(mediaId, mediaType: mediaType);
|
|
}
|
|
|
|
Future<bool> checkIsFavorite(String mediaId, {String mediaType = 'movie'}) {
|
|
return _neoClient.checkIsFavorite(mediaId, mediaType: mediaType);
|
|
}
|
|
|
|
// ---- Reactions ----
|
|
Future<Map<String, int>> getReactionCounts(
|
|
String mediaType, String mediaId) {
|
|
return _neoClient.getReactionCounts(
|
|
mediaType: mediaType,
|
|
mediaId: mediaId,
|
|
);
|
|
}
|
|
|
|
Future<void> setReaction(
|
|
String mediaType, String mediaId, String reactionType) {
|
|
return _neoClient.setReaction(
|
|
mediaType: mediaType,
|
|
mediaId: mediaId,
|
|
reactionType: reactionType,
|
|
);
|
|
}
|
|
|
|
Future<List<UserReaction>> getMyReactions() {
|
|
return _neoClient.getMyReactions();
|
|
}
|
|
|
|
// Get single user reaction for specific media
|
|
Future<UserReaction?> getMyReaction(String mediaType, String mediaId) async {
|
|
final reactions = await _neoClient.getMyReactions();
|
|
try {
|
|
return reactions.firstWhere(
|
|
(r) => r.mediaType == mediaType && r.mediaId == mediaId,
|
|
);
|
|
} catch (e) {
|
|
return null; // No reaction found
|
|
}
|
|
}
|
|
|
|
// ---- External IDs (IMDb) ----
|
|
Future<String?> getImdbId(String mediaId, String mediaType) async {
|
|
return _neoClient.getExternalIds(mediaId, mediaType);
|
|
}
|
|
|
|
// ---- Auth ----
|
|
Future<void> register(String name, String email, String password) {
|
|
return _neoClient.register(
|
|
name: name,
|
|
email: email,
|
|
password: password,
|
|
).then((_) {}); // старый код ничего не возвращал
|
|
}
|
|
|
|
Future<AuthResponse> login(String email, String password) async {
|
|
try {
|
|
return await _neoClient.login(email: email, password: password);
|
|
} catch (e) {
|
|
final errorMessage = e.toString();
|
|
if (errorMessage.contains('Account not activated') ||
|
|
errorMessage.contains('not verified') ||
|
|
errorMessage.contains('Please verify your email')) {
|
|
throw UnverifiedAccountException(email, message: errorMessage);
|
|
}
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<AuthResponse> verify(String email, String code) {
|
|
return _neoClient.verifyEmail(email: email, code: code);
|
|
}
|
|
|
|
Future<void> resendCode(String email) {
|
|
return _neoClient.resendVerificationCode(email);
|
|
}
|
|
|
|
Future<void> deleteAccount() {
|
|
return _neoClient.deleteAccount();
|
|
}
|
|
} |