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

47 lines
1.9 KiB
Dart

import 'dart:convert';
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';
import 'package:http/http.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 Response result = await apiClient.postJsonForResponse(ApiConsts.selectDeviceImei, mapDevice);
final SelectDeviceByImeiRespModelElement selectDeviceByImeiRespModelElement = SelectDeviceByImeiRespModelElement.fromJson(jsonDecode(result.body)['Patient_SELECTDeviceIMEIbyIMEIList'][0]);
loggerService.logInfo(result.body);
if (result !=null) {
return Right(selectDeviceByImeiRespModelElement);
} else {
loggerService.errorLogs(result.toString());
return Left(ServerFailure(result.toString()));
}
} on APIException catch (e) {
loggerService.errorLogs(e.toString());
return Left(ServerFailure(apiError?.errorMessage ?? e.message));
} catch (e) {
loggerService.errorLogs(e.toString());
return Left(ServerFailure(e.toString()));
}
}
}