refactor(apps): simplify API layer by removing redundant wrapper classes
- Remove ApiClientWrapper and MockApiClientWrapper - Simplify IApiClient interface - Update dependency injection configuration - Optimize calendar service and AG-UI chat models
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:dio/dio.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../api/api_client.dart';
|
||||
import '../api/i_api_client.dart';
|
||||
import '../api/mock_api_client.dart';
|
||||
import '../storage/token_storage.dart';
|
||||
import '../config/env.dart';
|
||||
import '../../features/auth/data/auth_api.dart';
|
||||
@@ -13,20 +15,27 @@ import '../../features/calendar/ui/calendar_state_manager.dart';
|
||||
final sl = GetIt.instance;
|
||||
|
||||
Future<void> configureDependencies() async {
|
||||
if (sl.isRegistered<ApiClient>()) {
|
||||
if (sl.isRegistered<IApiClient>()) {
|
||||
await sl.reset();
|
||||
}
|
||||
|
||||
final dio = Dio(BaseOptions(baseUrl: Env.apiUrl));
|
||||
final secureStorage = const FlutterSecureStorage();
|
||||
final tokenStorage = SecureTokenStorage(secureStorage);
|
||||
final IApiClient apiClient;
|
||||
final SecureTokenStorage tokenStorage;
|
||||
|
||||
final apiClient = ApiClient(
|
||||
baseUrl: Env.apiUrl,
|
||||
tokenStorage: tokenStorage,
|
||||
dio: dio,
|
||||
);
|
||||
sl.registerSingleton<ApiClient>(apiClient);
|
||||
if (Env.isMockApi) {
|
||||
apiClient = MockApiClient();
|
||||
tokenStorage = SecureTokenStorage(const FlutterSecureStorage());
|
||||
} else {
|
||||
final dio = Dio(BaseOptions(baseUrl: Env.apiUrl));
|
||||
tokenStorage = SecureTokenStorage(const FlutterSecureStorage());
|
||||
apiClient = ApiClient(
|
||||
baseUrl: Env.apiUrl,
|
||||
tokenStorage: tokenStorage,
|
||||
dio: dio,
|
||||
);
|
||||
}
|
||||
|
||||
sl.registerSingleton<IApiClient>(apiClient);
|
||||
|
||||
final authApi = AuthApi(apiClient);
|
||||
sl.registerSingleton<AuthApi>(authApi);
|
||||
@@ -37,16 +46,17 @@ Future<void> configureDependencies() async {
|
||||
);
|
||||
sl.registerSingleton<AuthRepository>(authRepository);
|
||||
|
||||
apiClient.setRefreshCallback((token) async {
|
||||
try {
|
||||
await authRepository.refreshSession(token);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (!Env.isMockApi) {
|
||||
(apiClient as ApiClient).setRefreshCallback((token) async {
|
||||
try {
|
||||
await authRepository.refreshSession(token);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sl.registerSingleton<AuthBloc>(AuthBloc(authRepository));
|
||||
|
||||
sl.registerSingleton<CalendarStateManager>(CalendarStateManager());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user