You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/lib/features/authentication/authentication_repo.dart

45 lines
1.7 KiB
Dart

import 'package:dartz/dartz.dart';
import 'package:hmg_patient_app_new/core/api/api_client.dart';
import 'package:hmg_patient_app_new/core/exceptions/api_exception.dart';
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
2 months ago
import 'package:hmg_patient_app_new/features/authentication/models/select_device_by_imei.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';
2 months ago
import 'package:http/http.dart';
abstract class AuthenticationRepo {
2 months ago
Future<Either<Failure, SelectDeviceByImeiRespModelElement?>> selectDeviceByImei({required String deviceIMEI});
}
class AuthenticationRepoImp implements AuthenticationRepo {
final ApiClient apiClient;
final LoggerService loggerService;
AuthenticationRepoImp({required this.loggerService, required this.apiClient});
@override
2 months ago
Future<Either<Failure, SelectDeviceByImeiRespModelElement?>> selectDeviceByImei({required String deviceIMEI}) async {
final mapDevice = {"": deviceIMEI};
2 months ago
final String apiUrl = "https://hmgwebservices.com/Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI" ;
try {
final Response result = await apiClient.postJsonForResponse(apiUrl, mapDevice);
if (result !=null) {
return Right(null);
} else {
loggerService.errorLogs(result.toString());
return Left(ServerFailure(result.toString()));
}
} on APIException catch (e) {
APIError? apiError;
if (e.error is APIError) {
apiError = e.error as APIError;
}
loggerService.errorLogs(e.toString());
return Left(ServerFailure(apiError?.errorMessage ?? e.message));
} catch (e) {
loggerService.errorLogs(e.toString());
return Left(ServerFailure(e.toString()));
}
}
2 months ago
}