From 0632af3fb56992f869b949859f8cd17e8eb91178 Mon Sep 17 00:00:00 2001 From: Mohammad Aljammal Date: Mon, 15 Feb 2021 14:56:25 +0200 Subject: [PATCH] Fix the Authentication Pharmacy --- lib/core/service/client/base_app_client.dart | 24 ++++++++++------- .../PrescriptionDeliveryViewModel.dart | 26 +++++++++++++++++++ lib/locator.dart | 2 ++ 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 lib/core/viewModels/PrescriptionDeliveryViewModel.dart diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index c7405608..429303bd 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -46,7 +46,10 @@ class BaseAppClient { //Map profile = await sharedPref.getObj(DOCTOR_PROFILE); var pharmacyToken = await sharedPref.getString(PHARMACY_AUTORZIE_TOKEN); var user = await sharedPref.getObject(USER_PROFILE); - + Map headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }; if (!isExternal) { String token = await sharedPref.getString(TOKEN); var languageID = @@ -104,7 +107,15 @@ class BaseAppClient { ? body['PatientID'] : user['PatientID']; body['PatientOutSA'] = user['OutSA']; - body['SessionID'] = SESSION_ID; //getSessionId(token); + body['SessionID'] = SESSION_ID; //getSe + headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': pharmacyToken, + 'Mobilenumber': user['MobileNumber'].toString(), + 'Statictoken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', + 'Username': user['PatientID'].toString(), + }; } } } @@ -115,14 +126,7 @@ class BaseAppClient { if (await Utils.checkConnection()) { final response = await http.post(url.trim(), body: json.encode(body), - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'Authorization': pharmacyToken, - 'Mobilenumber': user['MobileNumber'].toString(), - 'Statictoken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', - 'Username': user['PatientID'].toString(), - }); + headers: headers); final int statusCode = response.statusCode; print("statusCode :$statusCode"); if (statusCode < 200 || statusCode >= 400 || json == null) { diff --git a/lib/core/viewModels/PrescriptionDeliveryViewModel.dart b/lib/core/viewModels/PrescriptionDeliveryViewModel.dart new file mode 100644 index 00000000..e9731bae --- /dev/null +++ b/lib/core/viewModels/PrescriptionDeliveryViewModel.dart @@ -0,0 +1,26 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; + +import '../../locator.dart'; + +class PrescriptionDeliveryViewModel extends BaseViewModel{ + + CustomerAddressesService _customerAddressesService = locator(); + + List get addressesList => _customerAddressesService.addressesList; + + Future getCustomerAddresses() async { + setState(ViewState.Busy); + await _customerAddressesService.getCustomerAddresses( + ); + if (_customerAddressesService.hasError) { + error = _customerAddressesService.error; + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Idle); + } + } + + +} \ No newline at end of file diff --git a/lib/locator.dart b/lib/locator.dart index 0dfca5af..4d7f1e50 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -69,6 +69,7 @@ import 'core/service/parmacyModule/parmacy_module_service.dart'; import 'core/service/offers_service.dart'; import 'core/service/pharmacy_categorise_service.dart'; import 'core/viewModels/AlHabibMedicalService/health-calculator/Bariatrics-viewmodel.dart'; +import 'core/viewModels/PrescriptionDeliveryViewModel.dart'; import 'core/viewModels/TermsConditionsViewModel.dart'; import 'core/viewModels/all_habib_medical_services/e_referral_view_model.dart'; import 'core/viewModels/appointment_rate_view_model.dart'; @@ -255,6 +256,7 @@ void setupLocator() { locator.registerFactory(() => EyeViewModel()); locator.registerFactory(() => ActiveMedicationsViewModel()); locator.registerFactory(() => AskDoctorViewModel()); + locator.registerFactory(() => PrescriptionDeliveryViewModel()); locator.registerFactory(() => AllergiesViewModel()); locator.registerFactory(() => HomeHealthCareViewModel());