fix : change app architecture

feat : add some method to local storage
This commit is contained in:
2025-05-14 09:42:44 +03:30
parent e11ef1990c
commit feb3df6a06
50 changed files with 1007 additions and 70 deletions

View File

@@ -0,0 +1,23 @@
import '../models/response/auth/auth_response_model.dart';
import '../models/response/captcha/captcha_response_model.dart';
abstract class AuthRepository {
Future<AuthResponseModel?> login({
required Map<String, dynamic> authRequest,
});
Future<CaptchaResponseModel?> captcha();
Future<void> logout();
Future<bool> hasAuthenticated();
Future<AuthResponseModel?> loginWithRefreshToken({
required Map<String, dynamic> authRequest,
});
}

View File

@@ -0,0 +1,100 @@
import 'package:rasadyar_core/core.dart';
import '../models/response/auth/auth_response_model.dart';
import '../models/response/captcha/captcha_response_model.dart';
import 'auth_repository.dart';
class AuthRepositoryImpl implements AuthRepository {
final DioRemote _httpClient;
final String _BASE_URL = 'auth/api/v1/';
AuthRepositoryImpl(this._httpClient);
@override
Future<AuthResponseModel?> login({
required Map<String, dynamic> authRequest,
}) async {
final response = await safeCall<DioResponse<AuthResponseModel>>(
call:
() async => await _httpClient.post<AuthResponseModel>(
'$_BASE_URL/login/',
data: authRequest,
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
);
return response?.data;
}
@override
Future<CaptchaResponseModel?> captcha() async {
final response = await safeCall<DioResponse<CaptchaResponseModel>>(
call:
() async => await _httpClient.post<CaptchaResponseModel>(
'$_BASE_URL/login/',
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
);
return response?.data;
}
@override
Future<AuthResponseModel?> loginWithRefreshToken({
required Map<String, dynamic> authRequest,
}) async {
final response = await safeCall<DioResponse<AuthResponseModel>>(
call:
() async => await _httpClient.post<AuthResponseModel>(
'$_BASE_URL/login/',
data: authRequest,
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
);
return response?.data;
}
@override
Future<void> logout() {
// TODO: implement logout
throw UnimplementedError();
}
@override
Future<bool> hasAuthenticated() async {
final response = await safeCall<DioResponse<bool>>(
call:
() async => await _httpClient.get<bool>(
'$_BASE_URL/login/',
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
);
return response?.data ?? false;
}
}