initial commit

pull/3/head
Sultan khan 2 months ago
parent d3aff9f93d
commit 4e010bb2cf

@ -42,11 +42,20 @@ PODS:
- file_picker (0.0.1):
- DKImagePickerController/PhotoGallery
- Flutter
- Firebase/Analytics (11.15.0):
- Firebase/Core
- Firebase/Core (11.15.0):
- Firebase/CoreOnly
- FirebaseAnalytics (~> 11.15.0)
- Firebase/CoreOnly (11.15.0):
- FirebaseCore (~> 11.15.0)
- Firebase/Messaging (11.15.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 11.15.0)
- firebase_analytics (11.6.0):
- Firebase/Analytics (= 11.15.0)
- firebase_core
- Flutter
- firebase_core (3.15.2):
- Firebase/CoreOnly (= 11.15.0)
- Flutter
@ -54,6 +63,24 @@ PODS:
- Firebase/Messaging (= 11.15.0)
- firebase_core
- Flutter
- FirebaseAnalytics (11.15.0):
- FirebaseAnalytics/Default (= 11.15.0)
- FirebaseCore (~> 11.15.0)
- FirebaseInstallations (~> 11.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- FirebaseAnalytics/Default (11.15.0):
- FirebaseCore (~> 11.15.0)
- FirebaseInstallations (~> 11.0)
- GoogleAppMeasurement/Default (= 11.15.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- FirebaseCore (11.15.0):
- FirebaseCoreInternal (~> 11.15.0)
- GoogleUtilities/Environment (~> 8.1)
@ -107,6 +134,32 @@ PODS:
- Flutter
- Google-Maps-iOS-Utils (< 7.0, >= 5.0)
- GoogleMaps (< 10.0, >= 8.4)
- GoogleAdsOnDeviceConversion (2.1.0):
- GoogleUtilities/Logger (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- nanopb (~> 3.30910.0)
- GoogleAppMeasurement/Core (11.15.0):
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- GoogleAppMeasurement/Default (11.15.0):
- GoogleAdsOnDeviceConversion (= 2.1.0)
- GoogleAppMeasurement/Core (= 11.15.0)
- GoogleAppMeasurement/IdentitySupport (= 11.15.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- GoogleAppMeasurement/IdentitySupport (11.15.0):
- GoogleAppMeasurement/Core (= 11.15.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- GoogleDataTransport (10.1.0):
- nanopb (~> 3.30910.0)
- PromisesObjC (~> 2.4)
@ -125,6 +178,9 @@ PODS:
- GoogleUtilities/Logger (8.1.0):
- GoogleUtilities/Environment
- GoogleUtilities/Privacy
- GoogleUtilities/MethodSwizzler (8.1.0):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilities/Network (8.1.0):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
@ -216,6 +272,7 @@ DEPENDENCIES:
- device_calendar (from `.symlinks/plugins/device_calendar/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- FLAnimatedImage
@ -249,12 +306,15 @@ SPEC REPOS:
- DKImagePickerController
- DKPhotoGallery
- Firebase
- FirebaseAnalytics
- FirebaseCore
- FirebaseCoreInternal
- FirebaseInstallations
- FirebaseMessaging
- FLAnimatedImage
- Google-Maps-iOS-Utils
- GoogleAdsOnDeviceConversion
- GoogleAppMeasurement
- GoogleDataTransport
- GoogleMaps
- GoogleUtilities
@ -288,6 +348,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/device_info_plus/ios"
file_picker:
:path: ".symlinks/plugins/file_picker/ios"
firebase_analytics:
:path: ".symlinks/plugins/firebase_analytics/ios"
firebase_core:
:path: ".symlinks/plugins/firebase_core/ios"
firebase_messaging:
@ -345,8 +407,10 @@ SPEC CHECKSUMS:
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
file_picker: b159e0c068aef54932bb15dc9fd1571818edaf49
Firebase: d99ac19b909cd2c548339c2241ecd0d1599ab02e
firebase_analytics: bf93e20703c95030404d6ddbb1adf05bf5c3885b
firebase_core: 99a37263b3c27536063a7b601d9e2a49400a433c
firebase_messaging: bf6697c61f31c7cc0f654131212ff04c0115c2c7
FirebaseAnalytics: 6433dfd311ba78084fc93bdfc145e8cb75740eae
FirebaseCore: efb3893e5b94f32b86e331e3bd6dadf18b66568e
FirebaseCoreInternal: 9afa45b1159304c963da48addb78275ef701c6b4
FirebaseInstallations: 317270fec08a5d418fdbc8429282238cab3ac843
@ -362,6 +426,8 @@ SPEC CHECKSUMS:
geolocator_apple: 66b711889fd333205763b83c9dcf0a57a28c7afd
Google-Maps-iOS-Utils: 66d6de12be1ce6d3742a54661e7a79cb317a9321
google_maps_flutter_ios: e31555a04d1986ab130f2b9f24b6cdc861acc6d3
GoogleAdsOnDeviceConversion: 2be6297a4f048459e0ae17fad9bfd2844e10cf64
GoogleAppMeasurement: 700dce7541804bec33db590a5c496b663fbe2539
GoogleDataTransport: aae35b7ea0c09004c3797d53c8c41f66f219d6a7
GoogleMaps: 8939898920281c649150e0af74aa291c60f2e77d
GoogleUtilities: 00c88b9a86066ef77f0da2fab05f65d7768ed8e1

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/api_consts.dart';
@ -10,7 +11,6 @@ import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';
import 'package:http/http.dart' as http;
abstract class ApiClient {
Future<void> post(
String endPoint, {
@ -75,8 +75,10 @@ class ApiClientImp implements ApiClient {
final _analytics = getIt<GAnalytics>();
final LoggerService loggerService;
ApiClientImp({required this.loggerService});
@override
post(String endPoint,
{required Map<String, dynamic> body,
required Function(dynamic response, int statusCode) onSuccess,
@ -98,21 +100,15 @@ class ApiClientImp implements ApiClient {
}
try {
var user = appState.getAuthenticatedUser;
Map<String, String> headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
Map<String, String> headers = {'Content-Type': 'application/json', 'Accept': 'application/json'};
if (!isExternal) {
String? token = appState.appAuthToken;
String? languageID =
(appState.postParamsObject?.languageID == 1 ? 'ar' : 'en') ?? 'ar';
String? languageID = (appState.postParamsObject?.languageID == 1 ? 'ar' : 'en') ?? 'ar';
if (endPoint == ApiConsts.sendActivationCode) {
languageID = 'en';
}
if (body.containsKey('SetupID')) {
body['SetupID'] = body.containsKey('SetupID')
? body['SetupID'] ?? body['']
: SETUP_ID;
body['SetupID'] = body.containsKey('SetupID') ? body['SetupID'] ?? body[''] : SETUP_ID;
} else {}
if (body.containsKey('LanguageID')) {
@ -127,90 +123,71 @@ class ApiClientImp implements ApiClient {
}
if (body.containsKey('isDentalAllowedBackend')) {
body['isDentalAllowedBackend'] =
body.containsKey('isDentalAllowedBackend')
? body['isDentalAllowedBackend'] ?? IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND;
body['isDentalAllowedBackend'] = body.containsKey('isDentalAllowedBackend')
? body['isDentalAllowedBackend'] ?? IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND;
}
//Todo: I have converted it to string
body['DeviceTypeID'] = Platform.isIOS
? 1
? "1"
: await Utils.isGoogleServicesAvailable()
? 2
: 3;
? "2"
: "3";
if (!body.containsKey('IsPublicRequest')) {
// if (!body.containsKey('PatientType')) {
if (user != null && user.patientType != null) {
body['PatientType'] = user.patientType;
} else {
body['PatientType'] = PATIENT_TYPE;
body['PatientType'] = PATIENT_TYPE.toString();
}
// }
// body['PatientType'] = body.containsKey('PatientType')
// ? body['PatientType'] != null
// ? body['PatientType']
// : user['PatientType'] != null
// ? user['PatientType']
// : PATIENT_TYPE
// : PATIENT_TYPE;
// if (!body.containsKey('PatientTypeID')) {
if (user != null && user.patientType != null) {
body['PatientTypeID'] = user.patientType;
} else {
body['PatientType'] = PATIENT_TYPE_ID;
body['PatientType'] = PATIENT_TYPE_ID.toString();
}
// }
// body['PatientTypeID'] = body.containsKey('PatientTypeID')
// ? body['PatientTypeID'] != null
// ? body['PatientTypeID']
// : user['PatientType'] != null
// ? user['PatientType']
// : PATIENT_TYPE_ID
// : PATIENT_TYPE_ID;
if (user != null) {
body['TokenID'] = body['TokenID'] ?? token;
body['PatientID'] = body['PatientID'] ?? user.patientID;
body['PatientOutSA'] = body.containsKey('PatientOutSA')
? body['PatientOutSA'] ?? user.outSA
: user.outSA;
body['PatientOutSA'] = body.containsKey('PatientOutSA') ? body['PatientOutSA'] ?? user.outSA : user.outSA;
body['SessionID'] = getSessionId(body['TokenID'] ?? ""); //getSe
}
}
}
body['LanguageID'] = body['LanguageID'] ?? "1";
body['VersionID'] = body['VersionID'] ?? "18.7";
body['Channel'] = body['Channel'] ?? "3";
body['IPAdress'] = body['IPAdress'] ?? "10.20.10.20";
body['generalid'] = body['generalid'] ?? "Cs2020@2016\$2958";
body['Latitude'] = body['Latitude'] ?? "0.0";
body['Longitude'] = body['Longitude'] ?? "0.0";
body['DeviceTypeID'] = body['DeviceTypeID'] ??
(Platform.isIOS ? "1" : await Utils.isGoogleServicesAvailable() ? "2" : "3");
//"LanguageID":1,"VersionID":18.7,"Channel":3,"IPAdress":"10.20.10.20","generalid":"Cs2020@2016$2958","Latitude":0.0,"Longitude":0.0,"DeviceTypeID":2,"PatientType":1}
body.removeWhere((key, value) => value == null);
debugPrint("URL : $url");
final jsonBody = json.encode(body);
debugPrint(jsonBody);
// }
// return;
if (await Utils.checkConnection(
bypassConnectionCheck: bypassConnectionCheck)) {
final response = await http.post(Uri.parse(url.trim()),
body: json.encode(body), headers: headers);
log("bodi: ${json.encode(body)}");
log("bodi: ${Uri.parse(url.trim())}");
if (await Utils.checkConnection(bypassConnectionCheck: bypassConnectionCheck)) {
final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers);
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode >= 400) {
onFailure('Error While Fetching data', statusCode);
logApiEndpointError(
endPoint, 'Error While Fetching data', statusCode);
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
} else {
// var decoded = utf8.decode(response.bodyBytes);
var parsed;
// if (url.contains('Services/NHIC.svc/REST/GetPatientInfo')) {
// parsed = json.decode(sampleNHICResponse);
// } else {
parsed = json.decode(utf8.decode(response.bodyBytes));
// }
// print("Response: $parsed");
var parsed = json.decode(utf8.decode(response.bodyBytes));
log("parsed: ${parsed.toString()}");
if (isAllowAny) {
onSuccess(parsed, statusCode);
} else {
@ -219,10 +196,7 @@ class ApiClientImp implements ApiClient {
} else {
if (parsed['ErrorType'] == 4) {
//TODO : handle app update
logApiEndpointError(
endPoint,
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
statusCode);
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
}
if (parsed['ErrorType'] == 2) {
// todo: handle Logout
@ -238,72 +212,42 @@ class ApiClientImp implements ApiClient {
} else if (parsed['Result'] == 'OK') {
onSuccess(parsed, statusCode);
} else {
// if (parsed != null) {
// onSuccess(parsed, statusCode);
// } else {
onFailure(
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
statusCode);
logApiEndpointError(
endPoint,
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
statusCode);
// logout();
// }
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
}
} else if (parsed['MessageStatus'] == 1 ||
parsed['SMSLoginRequired'] == true) {
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
onSuccess(parsed, statusCode);
} else if (parsed['MessageStatus'] == 2 &&
parsed['IsAuthenticated']) {
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
if (parsed['SameClinicApptList'] != null) {
onSuccess(parsed, statusCode);
} else {
if (parsed['message'] == null &&
parsed['ErrorEndUserMessage'] == null) {
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
if (parsed['ErrorSearchMsg'] == null) {
onFailure("Server Error found with no available message",
statusCode);
logApiEndpointError(
endPoint,
"Server Error found with no available message",
statusCode);
onFailure("Server Error found with no available message", statusCode);
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
} else {
onFailure(parsed['ErrorSearchMsg'], statusCode);
logApiEndpointError(
endPoint, parsed['ErrorSearchMsg'], statusCode);
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
}
} else {
onFailure(
parsed['message'] ??
parsed['ErrorEndUserMessage'] ??
parsed['ErrorMessage'],
statusCode);
logApiEndpointError(endPoint,
parsed['message'] ?? parsed['message'], statusCode);
onFailure(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
}
}
}
// else if (!parsed['IsAuthenticated']) {
// await logout();
// }
else {
if (parsed['SameClinicApptList'] != null) {
onSuccess(parsed, statusCode);
} else {
if (parsed['message'] != null) {
onFailure(
parsed['message'] ?? parsed['message'], statusCode);
logApiEndpointError(endPoint,
parsed['message'] ?? parsed['message'], statusCode);
onFailure(parsed['message'] ?? parsed['message'], statusCode);
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
} else {
onFailure(
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
statusCode);
logApiEndpointError(
endPoint,
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
statusCode);
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
}
}
}
@ -312,20 +256,17 @@ class ApiClientImp implements ApiClient {
}
} else {
onFailure('Please Check The Internet Connection 1', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
}
} catch (e) {
print(e);
loggerService.errorLogs(e.toString());
if (e.toString().contains("ClientException")) {
onFailure('Something went wrong, plase try again', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
} else {
onFailure(e.toString(), -1);
}
_analytics.errorTracking
.log(endPoint, error: "api exception: $e - API Path: $url");
_analytics.errorTracking.log(endPoint, error: "api exception: $e - API Path: $url");
}
}
@ -356,10 +297,7 @@ class ApiClientImp implements ApiClient {
if (await Utils.checkConnection()) {
final response = await http.get(
Uri.parse(url.trim()),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'},
);
final int statusCode = response.statusCode;
// print("statusCode :$statusCode");
@ -373,8 +311,7 @@ class ApiClientImp implements ApiClient {
}
} else {
onFailure!('Please Check The Internet Connection', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
}
}
@ -390,8 +327,7 @@ class ApiClientImp implements ApiClient {
// print("body: $body");
if (await Utils.checkConnection()) {
headers!.addAll(
{'Content-Type': 'application/json', 'Accept': 'application/json'});
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
final response = await http.post(
Uri.parse(url.trim()),
body: json.encode(body),
@ -400,11 +336,7 @@ class ApiClientImp implements ApiClient {
final int statusCode = response.statusCode;
// print("statusCode :$statusCode");
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
simplePost(fullUrl,
onFailure: onFailure,
onSuccess: onSuccess,
body: body,
headers: headers);
simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers);
// print(response.body.toString());
@ -416,8 +348,7 @@ class ApiClientImp implements ApiClient {
}
} else {
onFailure!('Please Check The Internet Connection', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
}
}
@ -437,8 +368,7 @@ class ApiClientImp implements ApiClient {
}
if (await Utils.checkConnection()) {
headers.addAll(
{'Content-Type': 'application/json', 'Accept': 'application/json'});
headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
final response = await http.get(
Uri.parse(url.trim()),
headers: headers,
@ -447,11 +377,7 @@ class ApiClientImp implements ApiClient {
final int statusCode = response.statusCode;
// print("statusCode :$statusCode");
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
simpleGet(fullUrl,
onFailure: onFailure,
onSuccess: onSuccess,
headers: headers,
queryParams: queryParams);
simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams);
if (statusCode < 200 || statusCode >= 400) {
onFailure!('Error While Fetching data', statusCode);
@ -461,8 +387,7 @@ class ApiClientImp implements ApiClient {
}
} else {
onFailure!('Please Check The Internet Connection', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
}
}
@ -475,8 +400,7 @@ class ApiClientImp implements ApiClient {
// print("URL Query String: $url");
if (await Utils.checkConnection()) {
headers!.addAll(
{'Content-Type': 'application/json', 'Accept': 'application/json'});
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
final response = await http.put(
Uri.parse(url.trim()),
body: json.encode(body),
@ -486,11 +410,7 @@ class ApiClientImp implements ApiClient {
final int statusCode = response.statusCode;
// print("statusCode :$statusCode");
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
simplePut(fullUrl,
onFailure: onFailure,
onSuccess: onSuccess,
headers: headers,
body: body);
simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body);
if (statusCode < 200 || statusCode >= 400) {
onFailure!('Error While Fetching data', statusCode);
@ -500,8 +420,7 @@ class ApiClientImp implements ApiClient {
}
} else {
onFailure!('Please Check The Internet Connection', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
}
}
@ -521,8 +440,7 @@ class ApiClientImp implements ApiClient {
}
if (await Utils.checkConnection()) {
headers!.addAll(
{'Content-Type': 'application/json', 'Accept': 'application/json'});
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
final response = await http.delete(
Uri.parse(url.trim()),
headers: headers,
@ -531,11 +449,7 @@ class ApiClientImp implements ApiClient {
final int statusCode = response.statusCode;
// print("statusCode :$statusCode");
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
simpleDelete(fullUrl,
onFailure: onFailure,
onSuccess: onSuccess,
queryParams: queryParams,
headers: headers);
simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers);
if (statusCode < 200 || statusCode >= 400) {
onFailure!('Error While Fetching data', statusCode);
@ -545,13 +459,11 @@ class ApiClientImp implements ApiClient {
}
} else {
onFailure!('Please Check The Internet Connection', -1);
_analytics.errorTracking
.log("internet_connectivity", error: "no internet available");
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
}
}
Future<bool> handleUnauthorized(int statusCode,
{required String forUrl}) async {
Future<bool> handleUnauthorized(int statusCode, {required String forUrl}) async {
if (forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) {
final token = await generatePackagesToken();
ApiConsts.packagesAuthHeader['Authorization'] = 'Bearer $token';
@ -574,8 +486,7 @@ class ApiClientImp implements ApiClient {
};
String? token;
final completer = Completer();
simplePost(url, body: body, headers: {},
onSuccess: (dynamic stringResponse, int statusCode) {
simplePost(url, body: body, headers: {}, onSuccess: (dynamic stringResponse, int statusCode) {
if (statusCode == 200) {
var jsonResponse = json.decode(stringResponse);
token = jsonResponse['auth_token'];

@ -745,8 +745,8 @@ class ApiConsts {
static num VERSION_ID = 18.9;
static final String selectDeviceImei = 'https://hmgwebservices.com/Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI';
static final String sendActivationCode = 'https://hmgwebservices.com/Services/Authentication.svc/REST/SendActivationCodebyOTPNotificationType';
static final String selectDeviceImei = 'Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI';
static final String sendActivationCode = 'Services/Authentication.svc/REST/SendActivationCodebyOTPNotificationType';

@ -5,6 +5,7 @@ import 'package:hmg_patient_app_new/features/authentication/authentication_repo.
import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_repo.dart';
import 'package:hmg_patient_app_new/features/common/common_repo.dart';
import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_repo.dart';
import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
import 'package:hmg_patient_app_new/services/cache_service.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';
import 'package:logger/web.dart';
@ -15,10 +16,17 @@ GetIt getIt = GetIt.instance;
class AppDependencies {
static Future<void> addDependencies() async {
// Services
getIt.registerLazySingleton<LoggerService>(() => LoggerServiceImp(logger: Logger(printer: PrettyPrinter(lineLength: 0))));
getIt.registerLazySingleton<LoggerService>(() => LoggerServiceImp(logger: Logger(printer: PrettyPrinter(
methodCount: 2, // number of stack trace lines
errorMethodCount: 5, // number of stack trace lines for errors
lineLength: 100, // wrap width
colors: true, // colorful logs
printEmojis: true, // include emojis
),)));
final sharedPreferences = await SharedPreferences.getInstance();
getIt.registerLazySingleton<CacheService>(() => CacheServiceImp(sharedPreferences: sharedPreferences));
getIt.registerSingleton(AppState());
getIt.registerSingleton(GAnalytics());
getIt.registerLazySingleton<ApiClient>(() => ApiClientImp(loggerService: getIt()));
// Repositories

@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:async';
import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:hmg_patient_app_new/core/api/api_client.dart';
@ -7,7 +8,6 @@ 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});
@ -20,24 +20,35 @@ class AuthenticationRepoImp implements AuthenticationRepo {
AuthenticationRepoImp({required this.loggerService, required this.apiClient});
@override
Future<Either<Failure, SelectDeviceByImeiRespModelElement?>> selectDeviceByImei({required String firebaseToken}) async {
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()));
}
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(apiError?.errorMessage ?? e.message));
return Left(ServerFailure(e.message));
} catch (e) {
loggerService.errorLogs(e.toString());
return Left(ServerFailure(e.toString()));

@ -1,4 +1,4 @@
import 'package:hmg_patient_app/uitl/date_uitl.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
class AuthenticatedUser {
String? setupID;

Loading…
Cancel
Save