|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/api/api_client.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/exceptions/api_exception.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/models/select_device_by_imei.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
|
|
|
|
|
|
abstract class AuthenticationRepo {
|
|
|
|
|
Future<Either<Failure, SelectDeviceByImeiRespModelElement?>> selectDeviceByImei({required String firebaseToken});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AuthenticationRepoImp implements AuthenticationRepo {
|
|
|
|
|
final ApiClient apiClient;
|
|
|
|
|
final LoggerService loggerService;
|
|
|
|
|
|
|
|
|
|
AuthenticationRepoImp({required this.loggerService, required this.apiClient});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, SelectDeviceByImeiRespModelElement?>> selectDeviceByImei({
|
|
|
|
|
required String firebaseToken,
|
|
|
|
|
}) async {
|
|
|
|
|
final mapDevice = {"IMEI": firebaseToken};
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
final completer = Completer<Either<Failure, SelectDeviceByImeiRespModelElement?>>();
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
ApiConsts.selectDeviceImei,
|
|
|
|
|
body: mapDevice,
|
|
|
|
|
onSuccess: (response, statusCode) {
|
|
|
|
|
try {
|
|
|
|
|
final SelectDeviceByImeiRespModelElement model =
|
|
|
|
|
SelectDeviceByImeiRespModelElement.fromJson(response['Patient_SELECTDeviceIMEIbyIMEIList'][0]);
|
|
|
|
|
completer.complete(Right(model));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
completer.complete(Left(ServerFailure(e.toString())));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onFailure: (error, statusCode) {
|
|
|
|
|
loggerService.logInfo(("$error - $statusCode").toString());
|
|
|
|
|
completer.complete(Left(ServerFailure(error)));
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return await completer.future;
|
|
|
|
|
} on APIException catch (e) {
|
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
|
return Left(ServerFailure(e.message));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
|
return Left(ServerFailure(e.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|