Настройки, авторизация
This commit is contained in:
@@ -1,47 +1,64 @@
|
||||
import '../../../../core/errors/errors.dart';
|
||||
import '../../../../core/errors/result.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
import '../../domain/repositories/auth_repository.dart';
|
||||
import '../datasources/auth_local_datasource.dart';
|
||||
import '../datasources/auth_remote_datasource.dart';
|
||||
|
||||
class AuthRepositoryImpl implements AuthRepository {
|
||||
@override
|
||||
bool get isLoggedIn => false;
|
||||
final AuthRemoteDataSource remoteDataSource;
|
||||
final AuthLocalDataSource localDataSource;
|
||||
|
||||
AuthRepositoryImpl({
|
||||
required this.remoteDataSource,
|
||||
required this.localDataSource,
|
||||
});
|
||||
|
||||
@override
|
||||
Future<Result<User>> getCurrentUser() async {
|
||||
return const Result.failure(AppError.unauthorized(message: 'Not logged in'));
|
||||
Future<Result<User>> login(String username, String password) async {
|
||||
final result = await remoteDataSource.login(username, password);
|
||||
return result.fold(
|
||||
(error) => Result.failure(error),
|
||||
(response) async {
|
||||
await localDataSource.saveToken(response.accessToken);
|
||||
await localDataSource.saveRefreshToken(response.refreshToken);
|
||||
await localDataSource.saveUserId(response.userId);
|
||||
return Result.success(response.toDomainUser());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<User>> login(String email, String password) async {
|
||||
// TODO: Implement real login
|
||||
return Result.success(
|
||||
User(
|
||||
id: '1',
|
||||
email: email,
|
||||
name: 'Test User',
|
||||
),
|
||||
Future<Result<User>> register(String username, String password, String name) async {
|
||||
final result = await remoteDataSource.register(username, password, name);
|
||||
return result.fold(
|
||||
(error) => Result.failure(error),
|
||||
(response) async {
|
||||
await localDataSource.saveToken(response.accessToken);
|
||||
await localDataSource.saveRefreshToken(response.refreshToken);
|
||||
await localDataSource.saveUserId(response.userId);
|
||||
return Result.success(response.toDomainUser());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> logout() async {
|
||||
await remoteDataSource.logout();
|
||||
await localDataSource.removeToken();
|
||||
await localDataSource.removeUserId();
|
||||
return const Result.success(null);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<User>> register(String email, String password, String name) async {
|
||||
return Result.success(
|
||||
User(
|
||||
id: '1',
|
||||
email: email,
|
||||
name: name,
|
||||
),
|
||||
);
|
||||
Future<Result<User>> getCurrentUser() async {
|
||||
return await remoteDataSource.getCurrentUser();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> refreshToken() async {
|
||||
return const Result.success(null);
|
||||
return await remoteDataSource.refreshToken();
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isLoggedIn => false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user