mirror of
https://gitlab.com/foxixus/neomovies_mobile.git
synced 2025-10-28 01:58:50 +05:00
Initial commit
This commit is contained in:
73
lib/data/repositories/auth_repository.dart
Normal file
73
lib/data/repositories/auth_repository.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:neomovies_mobile/data/api/api_client.dart';
|
||||
import 'package:neomovies_mobile/data/models/user.dart';
|
||||
import 'package:neomovies_mobile/data/services/secure_storage_service.dart';
|
||||
import 'package:neomovies_mobile/data/exceptions/auth_exceptions.dart';
|
||||
|
||||
class AuthRepository {
|
||||
final ApiClient _apiClient;
|
||||
final SecureStorageService _storageService;
|
||||
|
||||
AuthRepository({
|
||||
required ApiClient apiClient,
|
||||
required SecureStorageService storageService,
|
||||
}) : _apiClient = apiClient,
|
||||
_storageService = storageService;
|
||||
|
||||
Future<void> login(String email, String password) async {
|
||||
final response = await _apiClient.login(email, password);
|
||||
if (!response.verified) {
|
||||
throw UnverifiedAccountException(email, message: 'Account not verified');
|
||||
}
|
||||
await _storageService.saveToken(response.token);
|
||||
await _storageService.saveUserData(
|
||||
name: response.user.name,
|
||||
email: response.user.email,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> register(String name, String email, String password) async {
|
||||
// Registration does not automatically log in the user in this flow.
|
||||
// It sends a verification code.
|
||||
await _apiClient.register(name, email, password);
|
||||
}
|
||||
|
||||
Future<void> verifyEmail(String email, String code) async {
|
||||
await _apiClient.verify(email, code);
|
||||
// After successful verification, the user should log in.
|
||||
}
|
||||
|
||||
Future<void> resendVerificationCode(String email) async {
|
||||
await _apiClient.resendCode(email);
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
await _storageService.deleteAll();
|
||||
}
|
||||
|
||||
Future<void> deleteAccount() async {
|
||||
// The AuthenticatedHttpClient will handle the token.
|
||||
await _apiClient.deleteAccount();
|
||||
await _storageService.deleteAll();
|
||||
}
|
||||
|
||||
Future<bool> isLoggedIn() async {
|
||||
final token = await _storageService.getToken();
|
||||
return token != null;
|
||||
}
|
||||
|
||||
Future<User?> getCurrentUser() async {
|
||||
final isLoggedIn = await this.isLoggedIn();
|
||||
if (!isLoggedIn) return null;
|
||||
|
||||
final userData = await _storageService.getUserData();
|
||||
if (userData['name'] == null || userData['email'] == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The User model requires an ID, which we don't have in storage.
|
||||
// For the profile screen, we only need name and email.
|
||||
// We'll create a User object with a placeholder ID.
|
||||
return User(id: 'local', name: userData['name']!, email: userData['email']!);
|
||||
}
|
||||
}
|
||||
20
lib/data/repositories/favorites_repository.dart
Normal file
20
lib/data/repositories/favorites_repository.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:neomovies_mobile/data/api/api_client.dart';
|
||||
import 'package:neomovies_mobile/data/models/favorite.dart';
|
||||
|
||||
class FavoritesRepository {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
FavoritesRepository(this._apiClient);
|
||||
|
||||
Future<List<Favorite>> getFavorites() async {
|
||||
return await _apiClient.getFavorites();
|
||||
}
|
||||
|
||||
Future<void> addFavorite(String mediaId, String mediaType, String title, String posterPath) async {
|
||||
await _apiClient.addFavorite(mediaId, mediaType, title, posterPath);
|
||||
}
|
||||
|
||||
Future<void> removeFavorite(String mediaId) async {
|
||||
await _apiClient.removeFavorite(mediaId);
|
||||
}
|
||||
}
|
||||
33
lib/data/repositories/movie_repository.dart
Normal file
33
lib/data/repositories/movie_repository.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:neomovies_mobile/data/api/api_client.dart';
|
||||
import 'package:neomovies_mobile/data/models/movie.dart';
|
||||
import 'package:neomovies_mobile/data/models/movie_preview.dart';
|
||||
|
||||
class MovieRepository {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
MovieRepository({required ApiClient apiClient}) : _apiClient = apiClient;
|
||||
|
||||
Future<List<Movie>> getPopularMovies({int page = 1}) async {
|
||||
return _apiClient.getPopularMovies(page: page);
|
||||
}
|
||||
|
||||
Future<List<Movie>> getTopRatedMovies({int page = 1}) async {
|
||||
return _apiClient.getTopRatedMovies(page: page);
|
||||
}
|
||||
|
||||
Future<List<Movie>> getUpcomingMovies({int page = 1}) async {
|
||||
return _apiClient.getUpcomingMovies(page: page);
|
||||
}
|
||||
|
||||
Future<Movie> getMovieById(String movieId) async {
|
||||
return _apiClient.getMovieById(movieId);
|
||||
}
|
||||
|
||||
Future<Movie> getTvById(String tvId) async {
|
||||
return _apiClient.getTvById(tvId);
|
||||
}
|
||||
|
||||
Future<List<Movie>> searchMovies(String query, {int page = 1}) async {
|
||||
return _apiClient.searchMovies(query, page: page);
|
||||
}
|
||||
}
|
||||
20
lib/data/repositories/reactions_repository.dart
Normal file
20
lib/data/repositories/reactions_repository.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:neomovies_mobile/data/api/api_client.dart';
|
||||
import 'package:neomovies_mobile/data/models/reaction.dart';
|
||||
|
||||
class ReactionsRepository {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
ReactionsRepository(this._apiClient);
|
||||
|
||||
Future<Map<String,int>> getReactionCounts(String mediaType,String mediaId) async {
|
||||
return await _apiClient.getReactionCounts(mediaType, mediaId);
|
||||
}
|
||||
|
||||
Future<UserReaction> getMyReaction(String mediaType,String mediaId) async {
|
||||
return await _apiClient.getMyReaction(mediaType, mediaId);
|
||||
}
|
||||
|
||||
Future<void> setReaction(String mediaType,String mediaId, String reactionType) async {
|
||||
await _apiClient.setReaction(mediaType, mediaId, reactionType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user