From 745545ffc3afb722c0d4ffc1da4e04d094569704 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 6 May 2021 14:57:11 +0300 Subject: [PATCH] add models --- ...on_code_for_doctor_app_response_model.dart | 181 ++++++++++++++++++ lib/core/service/authentication_service.dart | 19 +- .../viewModel/authentication_view_model.dart | 16 +- .../auth/verification_methods_screen.dart | 38 +--- 4 files changed, 213 insertions(+), 41 deletions(-) create mode 100644 lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart diff --git a/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart b/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart new file mode 100644 index 00000000..283e617f --- /dev/null +++ b/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart @@ -0,0 +1,181 @@ +class CheckActivationCodeForDoctorAppResponseModel { + String authenticationTokenID; + List listDoctorsClinic; + List list_DoctorProfile; + MemberInformation memberInformation; + + CheckActivationCodeForDoctorAppResponseModel( + {this.authenticationTokenID, + this.listDoctorsClinic, + this.memberInformation}); + + CheckActivationCodeForDoctorAppResponseModel.fromJson( + Map json) { + authenticationTokenID = json['AuthenticationTokenID']; + list_DoctorProfile = json['List_DoctorProfile']; + if (json['List_DoctorsClinic'] != null) { + listDoctorsClinic = new List(); + json['List_DoctorsClinic'].forEach((v) { + listDoctorsClinic.add(new ListDoctorsClinic.fromJson(v)); + }); + } + memberInformation = json['memberInformation'] != null + ? new MemberInformation.fromJson(json['memberInformation']) + : null; + } + + Map toJson() { + final Map data = new Map(); + data['AuthenticationTokenID'] = this.authenticationTokenID; + data['List_DoctorProfile'] = this.list_DoctorProfile; + if (this.listDoctorsClinic != null) { + data['List_DoctorsClinic'] = + this.listDoctorsClinic.map((v) => v.toJson()).toList(); + } + if (this.memberInformation != null) { + data['memberInformation'] = this.memberInformation.toJson(); + } + return data; + } +} + +class ListDoctorsClinic { + Null setupID; + int projectID; + int doctorID; + int clinicID; + bool isActive; + String clinicName; + + ListDoctorsClinic( + {this.setupID, + this.projectID, + this.doctorID, + this.clinicID, + this.isActive, + this.clinicName}); + + ListDoctorsClinic.fromJson(Map json) { + setupID = json['SetupID']; + projectID = json['ProjectID']; + doctorID = json['DoctorID']; + clinicID = json['ClinicID']; + isActive = json['IsActive']; + clinicName = json['ClinicName']; + } + + Map toJson() { + final Map data = new Map(); + data['SetupID'] = this.setupID; + data['ProjectID'] = this.projectID; + data['DoctorID'] = this.doctorID; + data['ClinicID'] = this.clinicID; + data['IsActive'] = this.isActive; + data['ClinicName'] = this.clinicName; + return data; + } +} + +class MemberInformation { + List clinics; + int doctorId; + String email; + int employeeId; + int memberId; + Null memberName; + Null memberNameArabic; + String preferredLanguage; + List roles; + + MemberInformation( + {this.clinics, + this.doctorId, + this.email, + this.employeeId, + this.memberId, + this.memberName, + this.memberNameArabic, + this.preferredLanguage, + this.roles}); + + MemberInformation.fromJson(Map json) { + if (json['clinics'] != null) { + clinics = new List(); + json['clinics'].forEach((v) { + clinics.add(new Clinics.fromJson(v)); + }); + } + doctorId = json['doctorId']; + email = json['email']; + employeeId = json['employeeId']; + memberId = json['memberId']; + memberName = json['memberName']; + memberNameArabic = json['memberNameArabic']; + preferredLanguage = json['preferredLanguage']; + if (json['roles'] != null) { + roles = new List(); + json['roles'].forEach((v) { + roles.add(new Roles.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + if (this.clinics != null) { + data['clinics'] = this.clinics.map((v) => v.toJson()).toList(); + } + data['doctorId'] = this.doctorId; + data['email'] = this.email; + data['employeeId'] = this.employeeId; + data['memberId'] = this.memberId; + data['memberName'] = this.memberName; + data['memberNameArabic'] = this.memberNameArabic; + data['preferredLanguage'] = this.preferredLanguage; + if (this.roles != null) { + data['roles'] = this.roles.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class Clinics { + bool defaultClinic; + int id; + String name; + + Clinics({this.defaultClinic, this.id, this.name}); + + Clinics.fromJson(Map json) { + defaultClinic = json['defaultClinic']; + id = json['id']; + name = json['name']; + } + + Map toJson() { + final Map data = new Map(); + data['defaultClinic'] = this.defaultClinic; + data['id'] = this.id; + data['name'] = this.name; + return data; + } +} + +class Roles { + String name; + int roleId; + + Roles({this.name, this.roleId}); + + Roles.fromJson(Map json) { + name = json['name']; + roleId = json['roleId']; + } + + Map toJson() { + final Map data = new Map(); + data['name'] = this.name; + data['roleId'] = this.roleId; + return data; + } +} diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index 18624d58..9f67a3b8 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -1,5 +1,6 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; @@ -15,22 +16,20 @@ import 'package:provider/provider.dart'; class AuthenticationService extends BaseService { List _imeiDetails = []; List get dashboardItemsList => _imeiDetails; - //TODO Change this to models NewLoginInformationModel _loginInfo = NewLoginInformationModel(); NewLoginInformationModel get loginInfo => _loginInfo; - Map _activationCodeVerificationScreenRes = {}; + SendActivationCodeForDoctorAppResponseModel _activationCodeVerificationScreenRes = SendActivationCodeForDoctorAppResponseModel(); - Map get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes; + SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes; SendActivationCodeForDoctorAppResponseModel _activationCodeForDoctorAppRes = SendActivationCodeForDoctorAppResponseModel(); SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _activationCodeForDoctorAppRes; - Map _checkActivationCodeForDoctorAppRes = {}; + CheckActivationCodeForDoctorAppResponseModel _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel(); - Map get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; + CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; Map _insertDeviceImeiRes = {}; - Map get insertDeviceImeiRes => _insertDeviceImeiRes; Future selectDeviceImei(imei) async { try { await baseAppClient.post(SELECT_DEVICE_IMEI, @@ -69,11 +68,11 @@ class AuthenticationService extends BaseService { Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async { hasError = false; - _activationCodeVerificationScreenRes = {}; + _activationCodeVerificationScreenRes = SendActivationCodeForDoctorAppResponseModel(); try { await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_VERIFICATION_SCREEN, onSuccess: (dynamic response, int statusCode) { - _activationCodeVerificationScreenRes = response; + _activationCodeVerificationScreenRes = SendActivationCodeForDoctorAppResponseModel.fromJson(response); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; @@ -104,13 +103,13 @@ class AuthenticationService extends BaseService { Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel)async { hasError = false; - _checkActivationCodeForDoctorAppRes = {}; + _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel(); try { await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP, onSuccess: (dynamic response, int statusCode) { // TODO improve the logic here Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear(); - _checkActivationCodeForDoctorAppRes = response; + _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel.fromJson(response); Provider.of(AppGlobal.CONTEX, listen: false).selectedClinicName = ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index a9986cec..f33ec782 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -3,6 +3,7 @@ import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; @@ -26,9 +27,9 @@ class AuthenticationViewModel extends BaseViewModel { List get imeiDetails => _authService.dashboardItemsList; List get hospitals => _hospitalsService.hospitals; NewLoginInformationModel get loginInfo => _authService.loginInfo; - get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; + SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; - get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; + CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; NewLoginInformationModel loggedUser; GetIMEIDetailsModel user; @@ -222,4 +223,15 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + + setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel){ + print("VerificationCode : " + + sendActivationCodeForDoctorAppResponseModel.verificationCode); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, + sendActivationCodeForDoctorAppResponseModel.vidaAuthTokenID); + sharedPref.setString(VIDA_REFRESH_TOKEN_ID, + sendActivationCodeForDoctorAppResponseModel.vidaRefreshTokenID); + sharedPref.setString(LOGIN_TOKEN_ID, + sendActivationCodeForDoctorAppResponseModel.logInTokenID); + } } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index ce783901..29188194 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -3,11 +3,8 @@ import 'dart:io' show Platform; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; -import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart'; @@ -381,15 +378,7 @@ class _VerificationMethodsScreenState extends State { Helpers.showErrorToast(model.error); GifLoaderDialogUtils.hideDialog(context); } else { - // TODO move it model - print("VerificationCode : " + - model.activationCodeForDoctorAppRes.verificationCode); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeForDoctorAppRes.vidaAuthTokenID); - sharedPref.setString(VIDA_REFRESH_TOKEN_ID, - model.activationCodeForDoctorAppRes.vidaRefreshTokenID); - sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeForDoctorAppRes.logInTokenID); + model.setDataAfterSendActivationSuccsess(model.activationCodeForDoctorAppRes); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); @@ -413,16 +402,7 @@ class _VerificationMethodsScreenState extends State { GifLoaderDialogUtils.hideDialog(context); Helpers.showErrorToast(model.error); } else { - //TODO Move it to view model - print("VerificationCode : " + - model.activationCodeVerificationScreenRes["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, - model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeVerificationScreenRes["LogInTokenID"]); + model.setDataAfterSendActivationSuccsess(model.activationCodeVerificationScreenRes); if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.hideDialog(context); @@ -535,20 +515,19 @@ class _VerificationMethodsScreenState extends State { sharedPref.setString( TOKEN, model - .checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); - if (model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != - null) { - loginProcessCompleted(model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); + .checkActivationCodeForDoctorAppRes.authenticationTokenID); + if (model.checkActivationCodeForDoctorAppRes.listDoctorsClinic.isNotEmpty) { + loginProcessCompleted(model.checkActivationCodeForDoctorAppRes.list_DoctorProfile[0]); sharedPref.setObj( CLINIC_NAME, model - .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + .checkActivationCodeForDoctorAppRes.listDoctorsClinic); } else { sharedPref.setObj( CLINIC_NAME, model - .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); - ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); + .checkActivationCodeForDoctorAppRes.listDoctorsClinic); + ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes.listDoctorsClinic[0].toJson()); getDocProfiles(clinic); } } @@ -586,4 +565,5 @@ class _VerificationMethodsScreenState extends State { Helpers.showErrorToast(err); }); } + }