fix : chicken app login and new module logic
This commit is contained in:
@@ -36,7 +36,6 @@ class ChickenRemoteDatasourceImp implements ChickenRemoteDatasource {
|
||||
required String token,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
eLog(_httpClient.baseUrl);
|
||||
var res = await _httpClient.get(
|
||||
'/roles-products/?role=Steward',
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import 'package:rasadyar_chicken/chicken.dart';
|
||||
import 'package:rasadyar_chicken/data/common/dio_error_handler.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/local/chicken_local.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/local/chicken_local_imp.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/remote/auth/auth_remote.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/remote/auth/auth_remote_imp.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/remote/chicken/chicken_remote.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/remote/chicken/chicken_remote_imp.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/auth/auth_repository.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/auth/auth_repository_imp.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/chicken/chicken_repository.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/chicken/chicken_repository_imp.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
GetIt diChicken = GetIt.instance;
|
||||
|
||||
Future<void> setupChickenDI() async {
|
||||
tLog("setup 1");
|
||||
diChicken.registerSingleton(DioErrorHandler());
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
|
||||
diChicken.registerLazySingleton<AppInterceptor>(
|
||||
() => AppInterceptor(
|
||||
//فعلا سامانه مرغ برای رفرش توکن چیزی ندارد
|
||||
// سامانه مرغ فعلاً رفرش توکن ندارد
|
||||
refreshTokenCallback: () async => null,
|
||||
saveTokenCallback: (String newToken) async {
|
||||
await tokenService.saveAccessToken(newToken);
|
||||
@@ -26,24 +34,43 @@ Future<void> setupChickenDI() async {
|
||||
instanceName: 'chickenInterceptor',
|
||||
);
|
||||
|
||||
var baseUrl = tokenService.baseurl.value;
|
||||
|
||||
diChicken.registerLazySingleton<DioRemote>(
|
||||
() =>
|
||||
DioRemote(interceptors: diChicken.get<AppInterceptor>(instanceName: 'chickenInterceptor')),
|
||||
() => DioRemote(
|
||||
baseUrl: baseUrl,
|
||||
interceptors: diChicken.get<AppInterceptor>(instanceName: 'chickenInterceptor'),
|
||||
),
|
||||
);
|
||||
|
||||
final dioRemote = diChicken.get<DioRemote>();
|
||||
await dioRemote.init();
|
||||
|
||||
diChicken.registerLazySingleton<AuthRemoteDataSourceImp>(
|
||||
diChicken.registerLazySingleton<AuthRemoteDataSource>(
|
||||
() => AuthRemoteDataSourceImp(diChicken.get<DioRemote>()),
|
||||
);
|
||||
|
||||
diChicken.registerLazySingleton<AuthRepositoryImpl>(
|
||||
() => AuthRepositoryImpl(diChicken.get<AuthRemoteDataSourceImp>()),
|
||||
diChicken.registerLazySingleton<AuthRepository>(
|
||||
() => AuthRepositoryImpl(diChicken.get<AuthRemoteDataSource>()),
|
||||
instanceName: 'oldRepo',
|
||||
);
|
||||
|
||||
diChicken.registerLazySingleton<ChickenRemoteDatasource>(
|
||||
() => ChickenRemoteDatasourceImp(diChicken.get<DioRemote>()),
|
||||
);
|
||||
|
||||
diChicken.registerLazySingleton<ChickenLocalDataSource>(() => ChickenLocalDataSourceImp());
|
||||
|
||||
diChicken.registerLazySingleton<ChickenRepository>(
|
||||
() => ChickenRepositoryImp(
|
||||
remote: diChicken.get<ChickenRemoteDatasource>(),
|
||||
local: diChicken.get<ChickenLocalDataSource>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> newSetupAuthDI(String newUrl) async {
|
||||
tLog("setup 2");
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
if (tokenService.baseurl.value == null) {
|
||||
await tokenService.saveBaseUrl(newUrl);
|
||||
@@ -52,7 +79,10 @@ Future<void> newSetupAuthDI(String newUrl) async {
|
||||
if (diChicken.isRegistered<DioRemote>()) {
|
||||
await diChicken.unregister<DioRemote>();
|
||||
diChicken.registerLazySingleton<DioRemote>(
|
||||
() => DioRemote(baseUrl: newUrl, interceptors: diChicken.get<AppInterceptor>()),
|
||||
() => DioRemote(
|
||||
baseUrl: newUrl,
|
||||
interceptors: diChicken.get<AppInterceptor>(instanceName: 'chickenInterceptor'),
|
||||
),
|
||||
);
|
||||
final dioRemote = diChicken.get<DioRemote>();
|
||||
await dioRemote.init();
|
||||
@@ -60,15 +90,38 @@ Future<void> newSetupAuthDI(String newUrl) async {
|
||||
|
||||
if (diChicken.isRegistered<AuthRemoteDataSource>()) {
|
||||
await diChicken.unregister<AuthRemoteDataSource>();
|
||||
diChicken.registerLazySingleton<AuthRemoteDataSourceImp>(
|
||||
diChicken.registerLazySingleton<AuthRemoteDataSource>(
|
||||
() => AuthRemoteDataSourceImp(diChicken.get<DioRemote>()),
|
||||
);
|
||||
}
|
||||
|
||||
if (diChicken.isRegistered<AuthRepositoryImpl>()) {
|
||||
await diChicken.unregister<AuthRepositoryImpl>();
|
||||
diChicken.registerLazySingleton<AuthRepositoryImpl>(
|
||||
if (diChicken.isRegistered<AuthRepository>(instanceName: 'oldRepo')) {
|
||||
await diChicken.unregister<AuthRepository>(instanceName: 'oldRepo');
|
||||
diChicken.registerLazySingleton<AuthRepository>(
|
||||
() => AuthRepositoryImpl(diChicken.get<AuthRemoteDataSource>()),
|
||||
instanceName: 'newRepo',
|
||||
);
|
||||
}
|
||||
|
||||
if (diChicken.isRegistered<ChickenRemoteDatasource>()) {
|
||||
await diChicken.unregister<ChickenRemoteDatasource>();
|
||||
diChicken.registerLazySingleton<ChickenRemoteDatasource>(
|
||||
() => ChickenRemoteDatasourceImp(diChicken.get<DioRemote>()),
|
||||
);
|
||||
}
|
||||
|
||||
if (diChicken.isRegistered<ChickenLocalDataSource>()) {
|
||||
await diChicken.unregister<ChickenLocalDataSource>();
|
||||
diChicken.registerLazySingleton<ChickenLocalDataSource>(() => ChickenLocalDataSourceImp());
|
||||
}
|
||||
|
||||
if (diChicken.isRegistered<ChickenRepository>()) {
|
||||
await diChicken.unregister<ChickenRepository>();
|
||||
diChicken.registerLazySingleton<ChickenRepository>(
|
||||
() => ChickenRepositoryImp(
|
||||
remote: diChicken.get<ChickenRemoteDatasource>(),
|
||||
local: diChicken.get<ChickenLocalDataSource>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:rasadyar_chicken/data/data_source/local/chicken_local_imp.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/remote/chicken/chicken_remote_imp.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/local/chicken_local.dart';
|
||||
import 'package:rasadyar_chicken/data/data_source/remote/chicken/chicken_remote.dart';
|
||||
import 'package:rasadyar_chicken/data/models/local/widely_used_local_model.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/change_password/change_password_request_model.dart';
|
||||
import 'package:rasadyar_chicken/data/models/request/conform_allocation/conform_allocation.dart';
|
||||
@@ -29,8 +29,8 @@ import 'package:rasadyar_core/core.dart';
|
||||
import 'chicken_repository.dart';
|
||||
|
||||
class ChickenRepositoryImp implements ChickenRepository {
|
||||
final ChickenRemoteDatasourceImp remote;
|
||||
final ChickenLocalDataSourceImp local;
|
||||
final ChickenRemoteDatasource remote;
|
||||
final ChickenLocalDataSource local;
|
||||
|
||||
ChickenRepositoryImp({required this.remote, required this.local});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user