diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index d898502..19ec9fb 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -264,6 +264,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; import 'package:http/io_client.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/exceptions/api_exception.dart'; import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/models/generic_mapper_model.dart'; @@ -379,7 +380,7 @@ class APIError { class ApiResponse { final dynamic totalItemsCount; - final T data; + final T? data; final dynamic messageStatus; final dynamic errorMessage; final dynamic errorEndUserMessage; @@ -391,8 +392,8 @@ class ApiResponse { String toRawJson() => json.encode(toJson()); factory ApiResponse.fromJson(Map json) => ApiResponse( - totalItemsCount: json["TotalItemsCount"] ?? json["totalItemsCount"] , - data: json["Data"] ?? json["data"], + totalItemsCount: json["TotalItemsCount"] ?? json["totalItemsCount"], + data: json["Data"] ?? json["data"], messageStatus: json["MessageStatus"] ?? json["messageStatus"], errorMessage: json["ErrorMessage"] ?? json["errorMessage"], errorEndUserMessage: json["ErrorEndUserMessage"] ?? json["errorEndUserMessage"], @@ -406,7 +407,7 @@ class ApiResponse { "ErrorEndUserMessage": errorEndUserMessage, }; - bool get isSuccess => messageStatus == 1 && (errorMessage==null || errorMessage!.isEmpty ); + bool get isSuccess => messageStatus == 1 && (errorMessage == null || errorMessage!.isEmpty); } APIException _throwAPIException(Response response) { @@ -474,6 +475,16 @@ class ApiClient { printLongLog("body:$bodyJson"); } + if (!_headers.containsKey('Authorization') && jsonObject is Map && jsonObject.containsKey('tokenID') && AppState().isLogged) { + _headers['Authorization'] = 'Bearer ${jsonObject['tokenID']}'; + } + + // Remove "logInTokenID" and "tokenID" from jsonObject if present + if (jsonObject is Map && AppState().isLogged) { + jsonObject.remove("logInTokenID"); + jsonObject.remove("tokenID"); + } + var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes, isFormData: isFormData); if (!kReleaseMode) { @@ -485,7 +496,7 @@ class ApiClient { // Handle authentication flag if present if (jsonData["IsAuthenticated"] != null) { print("IsAuthenticated Need to be upated: ${jsonData["IsAuthenticated"]}"); - // AppState().setIsAuthenticated = jsonData["IsAuthenticated"]; + // // AppState().setIsAuthenticated = jsonData["IsAuthenticated"]; } // Create ApiResponse from the json @@ -494,8 +505,7 @@ class ApiClient { if (apiResponse.isSuccess) { return factoryConstructor(jsonData); } else { - if(apiResponse.messageStatus == null || apiResponse.messageStatus != 1) { - + if (apiResponse.messageStatus == null || apiResponse.messageStatus != 1) { logger.i(apiResponse.errorMessage); throw APIException( APIException.OTHER, @@ -506,7 +516,7 @@ class ApiClient { response.statusCode, ), ); - }else { + } else { throw APIException( APIException.BAD_REQUEST, error: APIError( @@ -574,7 +584,6 @@ class ApiClient { url = url + '?' + queryString; } - var response = await _post( Uri.parse(url), body: requestBody, diff --git a/lib/api/api_mapper_class.dart b/lib/api/api_mapper_class.dart index 591477a..13c7e1b 100644 --- a/lib/api/api_mapper_class.dart +++ b/lib/api/api_mapper_class.dart @@ -18,6 +18,7 @@ import 'package:mohem_flutter_app/models/eit/get_eit_transaction_model.dart'; import 'package:mohem_flutter_app/models/generic_mapper_model.dart'; import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/models/get_mobile_login_info_list_model.dart'; +import 'package:mohem_flutter_app/models/get_time_card_summary_list_model.dart'; import 'package:mohem_flutter_app/models/itg/itg_main_response.dart'; import 'package:mohem_flutter_app/models/itg/itg_response_model.dart'; import 'package:mohem_flutter_app/models/member_login_list_model.dart'; @@ -105,7 +106,7 @@ class ApiClassMapper { case 'Mohemm_ITG_OffersDiscount_GetAll': return; case 'Mohemm_ITG_GetPageNotification': - return MohemmItgResponseItem(); + return MohemmItgResponseItem.fromJson(jsonDecode(jsonData)); case 'Mohemm_ITG_Survey_Response': return ItgMainRes(); case 'Mohemm_ITG_GetPageNotificationDetails': @@ -161,6 +162,8 @@ class ApiClassMapper { case 'GET_EIT_TRANSACTIONS': return CollectionTransaction(); case 'GET_TIME_CARD_SUMMARY': + // return (res.getTimeCardSummaryList?.length ?? 0) > 0 ? res.getTimeCardSummaryList!.first : null; + GetTimeCardSummaryList data = GetTimeCardSummaryList.fromRawJson(jsonEncode(jsonData)); return; case 'GET_DAY_HOURS_TYPE_DETAILS': return; diff --git a/lib/api/login_api_client.dart b/lib/api/login_api_client.dart index db811a9..0f0c589 100644 --- a/lib/api/login_api_client.dart +++ b/lib/api/login_api_client.dart @@ -26,9 +26,9 @@ class LoginApiClient { Map postParams = {}; postParams["DeviceToken"] = deviceToken; postParams["DeviceType"] = deviceType; - // return await ApiClient().postJsonForObject((json) { - // GenericResponseModel? responseData = GenericResponseModel.fromJson(json); - // print(jsonDecode(json["data"].first)); + // return await ApiClient().postJsonForObject((json) { + // GenericResponseModel? responseData = GenericResponseModel.fromJson(json); + // print(jsonDecode(json["data"].first)); // GetMobileLoginInfoListModel? modelData= GetMobileLoginInfoListModel.fromRawJson(jsonDecode(json["data"].first)); // print("getMobileLoginInfoNEW: ${modelData.toJson()}"); // // return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? (responseData.mohemmGetMobileLoginInfoList!.first) : null; @@ -43,7 +43,7 @@ class LoginApiClient { Future insertMobileLoginInfoNEW(String email, int sessionId, String employeeName, int loginType, String mobileNumber, String userName, String deviceToken, String deviceType) async { //String url = "${ApiConsts.authRest}Mohemm_Insert_MobileDeviceInfo"; - String url = "${ApiConsts.authRest}Mohemm_InsertMobileLoginInfo"; + String url = "${ApiConsts.authRest}Mohemm_InsertMobileLoginInfo"; Map postParams = { "MobileNumber": mobileNumber, "p_USER_NAME": userName, @@ -53,8 +53,7 @@ class LoginApiClient { "loginType": loginType, "employeeName": employeeName, "p_EMAIL_ADDRESS": email, - "gender":1, //todo - + "gender": 1, //todo }; postParams["deviceToken"] = deviceToken; postParams["deviceType"] = deviceType; @@ -68,19 +67,19 @@ class LoginApiClient { return ress; } - Future checkMobileAppVersion() async { + Future checkMobileAppVersion() async { String url = "${ApiConsts.authRest}CheckMobileAppVersion"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, returnJsonData: false); - ApiResponse res = ApiResponse.fromJson(response); + return ApiResponse.fromJson(response); - if (res.data == null || res.data!.isEmpty) { - return CheckMobileAppVersionModel(data: ""); // Handle the case where response data is null - } else { - CheckMobileAppVersionModel res = await ApiClassMapper().handleApiEndpoint(endpoint: "CheckMobileAppVersion", jsonData: response.data); - return res; - } + // if (res.data == null || res.data!.isEmpty) { + // return CheckMobileAppVersionModel(data: ""); // Handle the case where response data is null + // } else { + // CheckMobileAppVersionModel result = await ApiClassMapper().handleApiEndpoint(endpoint: "CheckMobileAppVersion", jsonData: response); + + // } } Future memberLogin(String username, String password) async { @@ -115,7 +114,7 @@ class LoginApiClient { postParams["logInTokenID"] = AppState().postParamsObject?.getLogInTokenID; dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams); ApiResponse res = ApiResponse.fromJson(response); - AppState().isLogged =true; + AppState().isLogged = true; return await ApiClassMapper().handleApiEndpoint(endpoint: "CheckActivationCode", jsonData: res.data); } @@ -131,12 +130,16 @@ class LoginApiClient { Future sendPublicActivationCode(String? mobileNumber, String? pUsername) async { String url = "${ApiConsts.authRest}SendPublicActivationCode"; // todo @zahoor, not found in swagger - Map postParams = {"mobileNumber": mobileNumber, "p_MOBILE_NUMBER": mobileNumber, "p_USER_NAME": pUsername, }; + Map postParams = { + "mobileNumber": mobileNumber, + "p_MOBILE_NUMBER": mobileNumber, + "p_USER_NAME": pUsername, + }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { ApiResponse res = ApiResponse.fromJson(json); - GenericResponseModel responseData = GenericResponseModel.fromJson(json); - AppState().postParamsObject?.setLogInTokenID = res.data['logInTokenID'] ?? AppState().postParamsObject?.getLogInTokenID; + GenericResponseModel responseData = GenericResponseModel.fromJson(json); + AppState().postParamsObject?.setLogInTokenID = res.data['logInTokenID'] ?? AppState().postParamsObject?.getLogInTokenID; AppState().postParamsObject?.setTokenID = res.data['logInTokenID']; return responseData; }, url, postParams); diff --git a/lib/api/monthly_attendance_api_client.dart b/lib/api/monthly_attendance_api_client.dart index e462373..caa7e95 100644 --- a/lib/api/monthly_attendance_api_client.dart +++ b/lib/api/monthly_attendance_api_client.dart @@ -1,6 +1,6 @@ - import 'dart:async'; +import 'package:mohem_flutter_app/api/api_mapper_class.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/models/generic_response_model.dart'; @@ -27,10 +27,19 @@ class MonthlyAttendanceApiClient { }; postParams.addAll(AppState().postParamsJson); - return await ApiClient().postJsonForObject((json) { - GenericResponseModel? responseData = GenericResponseModel.fromJson(json); - return (responseData.getTimeCardSummaryList?.length ?? 0) > 0 ? responseData.getTimeCardSummaryList!.first : null; - }, url, postParams); + + // ApiResponse responseData = await ApiClient().postJsonForObject((json) => json, url, postParams); + // GenericResponseModel data = GenericResponseModel.fromJson(responseData.data); + // return (data.getTimeCardSummaryList?.length ?? 0) > 0 ? data.getTimeCardSummaryList!.first : null; + + ApiResponse responseData = await ApiClient().postJsonForObject((json) => json, url, postParams); + print(responseData); + GenericResponseModel? data = GenericResponseModel.fromJson(responseData.data); + if (data != null) { + return (data.getTimeCardSummaryList != null && data.getTimeCardSummaryList!.isNotEmpty) ? data.getTimeCardSummaryList!.first : null; + } else { + return null; + } } Future> getDayHoursTypeDetails(String month, int year) async { @@ -52,7 +61,6 @@ class MonthlyAttendanceApiClient { }, url, postParams); } - Future getScheduleShiftsDetails(int pRTPID) async { String url = "${ApiConsts.erpRest}GET_SCHEDULE_SHIFTS_DETAILS"; Map postParams = { @@ -66,5 +74,4 @@ class MonthlyAttendanceApiClient { return (responseData.getScheduleShiftsDetailsList?.length ?? 0) > 0 ? responseData.getScheduleShiftsDetailsList!.first : null; }, url, postParams); } - -} \ No newline at end of file +} diff --git a/lib/api/my_team/my_team_api_client.dart b/lib/api/my_team/my_team_api_client.dart index 08484b4..28281cb 100644 --- a/lib/api/my_team/my_team_api_client.dart +++ b/lib/api/my_team/my_team_api_client.dart @@ -104,7 +104,7 @@ class MyTeamApiClient { return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json["Data"]); return responseData.getMenuEntriesList ?? []; - }, url, postParams); + }, url, postParams ); } Future?> getFavoriteReplacement() async { diff --git a/lib/models/get_time_card_summary_list_model.dart b/lib/models/get_time_card_summary_list_model.dart index becc1d2..813fb87 100644 --- a/lib/models/get_time_card_summary_list_model.dart +++ b/lib/models/get_time_card_summary_list_model.dart @@ -1,5 +1,7 @@ +import 'dart:convert'; + class GetTimeCardSummaryList { num? aBSENTDAYS; dynamic? aCTUALHRS; @@ -112,6 +114,11 @@ class GetTimeCardSummaryList { uNPAIDLEAVE = json['UNPAID_LEAVE']; } + + factory GetTimeCardSummaryList.fromRawJson(String str) => GetTimeCardSummaryList.fromJson(json.decode(str)); + + String toRawJson() => json.encode(toJson()); + Map toJson() { Map data = new Map(); data['ABSENT_DAYS'] = this.aBSENTDAYS; @@ -150,4 +157,9 @@ class GetTimeCardSummaryList { data['UNCOVERD_SHORTAGE_HRS'] = this.uNCOVERDSHORTAGEHRS; data['UNPAID_LEAVE'] = this.uNPAIDLEAVE; return data; - }} \ No newline at end of file + } + + + + +} \ No newline at end of file diff --git a/lib/ui/landing/widget/services_widget.dart b/lib/ui/landing/widget/services_widget.dart index 9707417..bf909b6 100644 --- a/lib/ui/landing/widget/services_widget.dart +++ b/lib/ui/landing/widget/services_widget.dart @@ -207,7 +207,7 @@ class ServicesWidget extends StatelessWidget { } else if (menuEntry.menUName == "MBL_PERINFO_SS") { Navigator.of(context).pushNamed(AppRoutes.profile); return; - } else if (menuEntry.menUName!.isNotEmpty && menuEntry.menUName!.substring(4, menuEntry.menUName!.length) == "MBL_EMPLOYEE_DOCUMENTS") { + } else if (menuEntry.menUName!= null && menuEntry.menUName!.isNotEmpty && menuEntry.menUName!.substring(4, menuEntry.menUName!.length) == "MBL_EMPLOYEE_DOCUMENTS") { Navigator.pushNamed(context, AppRoutes.myDocuments); return; } diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index 9555541..83e09fa 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -8,6 +8,7 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:mohem_flutter_app/api/api_client.dart'; // import 'package:huawei_hmsavailability/huawei_hmsavailability.dart'; import 'package:mohem_flutter_app/api/login_api_client.dart'; @@ -49,7 +50,7 @@ class _LoginScreenState extends State { TextEditingController username = TextEditingController(); TextEditingController password = TextEditingController(); - CheckMobileAppVersionModel? _checkMobileAppVersion; + ApiResponse? _checkMobileAppVersion; MemberLoginListModel? _memberLoginList; late final FirebaseMessaging _firebaseMessaging;