From 77d4291025f584d4be4af923941d0828ce821540 Mon Sep 17 00:00:00 2001 From: "mirza.shafique" Date: Tue, 20 Jun 2023 14:58:05 +0300 Subject: [PATCH] genaric models update --- lib/models/model/provider_model.dart | 110 +------------------------ lib/models/profile/categroy.dart | 15 ++-- lib/models/services/branch_model.dart | 13 ++- lib/models/services/service_model.dart | 49 ++++++----- 4 files changed, 47 insertions(+), 140 deletions(-) diff --git a/lib/models/model/provider_model.dart b/lib/models/model/provider_model.dart index 352f1e1..a406509 100644 --- a/lib/models/model/provider_model.dart +++ b/lib/models/model/provider_model.dart @@ -5,6 +5,7 @@ import 'dart:convert'; import 'package:mc_common_app/models/profile/categroy.dart'; +import 'package:mc_common_app/models/services/branch_model.dart'; ProviderModel branch2FromJson(String str) => ProviderModel.fromJson(json.decode(str)); @@ -59,7 +60,7 @@ class ProviderModelData { final int? allDocStatus; final bool? isValidSubscription; final String? userId; - final List? serviceProviderBranch; + final List? serviceProviderBranch; factory ProviderModelData.fromJson(Map json) => ProviderModelData( id: json["id"] == null ? null : json["id"], @@ -70,7 +71,7 @@ class ProviderModelData { allDocStatus: json["allDocStatus"] == null ? null : json["allDocStatus"], isValidSubscription: json["isValidSubscription"] == null ? null : json["isValidSubscription"], userId: json["userID"] == null ? null : json["userID"], - serviceProviderBranch: json["serviceProviderBranch"] == null ? null : List.from(json["serviceProviderBranch"].map((x) => ServiceProviderBranch.fromJson(x))), + serviceProviderBranch: json["serviceProviderBranch"] == null ? null : List.from(json["serviceProviderBranch"].map((x) => BranchModel.fromJson(x))), ); Map toJson() => { @@ -84,108 +85,3 @@ class ProviderModelData { }; } -class ServiceProviderBranch { - ServiceProviderBranch({ - this.id, - this.cityId, - this.cityName, - this.branchName, - this.branchDescription, - this.address, - this.latitude, - this.longitude, - this.status, - this.serviceProviderServices, - this.countryID, - this.countryName, - this.categories, - }); - - final int? id; - int? countryID; - String? countryName; - final int? cityId; - final dynamic? cityName; - final String? branchName; - final String? branchDescription; - final String? address; - final String? latitude; - final String? longitude; - final int? status; - final List? serviceProviderServices; - List? categories; - - factory ServiceProviderBranch.fromJson(Map json) => ServiceProviderBranch( - id: json["id"] == null ? null : json["id"], - countryID: 0, - countryName: "", - cityId: json["cityID"] == null ? null : json["cityID"], - cityName: json["cityName"], - branchName: json["branchName"] == null ? null : json["branchName"], - branchDescription: json["branchDescription"] == null ? null : json["branchDescription"], - address: json["address"] == null ? null : json["address"], - latitude: json["latitude"] == null ? null : json["latitude"], - longitude: json["longitude"] == null ? null : json["longitude"], - status: json["status"] == null ? null : json["status"], - serviceProviderServices: json["serviceProviderServices"] == null ? null : List.from(json["serviceProviderServices"].map((x) => ServiceProviderService.fromJson(x))), - categories: [], - ); - - Map toJson() => { - "id": id == null ? null : id, - "cityID": cityId == null ? null : cityId, - "cityName": cityName, - "branchName": branchName == null ? null : branchName, - "branchDescription": branchDescription == null ? null : branchDescription, - "address": address == null ? null : address, - "latitude": latitude == null ? null : latitude, - "longitude": longitude == null ? null : longitude, - "status": status == null ? null : status, - "serviceProviderServices": serviceProviderServices == null ? null : List.from(serviceProviderServices!.map((x) => x.toJson())), - }; -} - -class ServiceProviderService { - ServiceProviderService({ - this.serviceId, - this.serviceName, - this.serviceNameN, - this.categoryId, - this.categoryName, - this.serviceStatus, - this.isAllowAppointment, - this.customerLocationRange, - this.rangePricePerKm, - }); - - final int? serviceId; - final String? serviceName; - final String? serviceNameN; - final int? categoryId; - final String? categoryName; - final int? serviceStatus; - final bool? isAllowAppointment; - final int? customerLocationRange; - final String? rangePricePerKm; - - factory ServiceProviderService.fromJson(Map json) => ServiceProviderService( - serviceId: json["serviceID"] == null ? null : json["serviceID"], - serviceName: json["serviceName"] == null ? null : json["serviceName"], - serviceNameN: json["serviceNameN"] == null ? null : json["serviceNameN"], - categoryId: json["categoryID"] == null ? null : json["categoryID"], - categoryName: json["categoryName"] == null ? null : json["categoryName"], - serviceStatus: json["serviceStatus"] == null ? null : json["serviceStatus"], - isAllowAppointment: json["isAllowAppointment"] == null ? null : json["isAllowAppointment"], - customerLocationRange: json["customerLocationRange"] == null ? null : json["customerLocationRange"], - rangePricePerKm: json["rangePricePerKm"] == null ? null : json["rangePricePerKm"].toString(), - ); - - Map toJson() => { - "serviceID": serviceId == null ? null : serviceId, - "serviceName": serviceName == null ? null : serviceName, - "serviceNameN": serviceNameN == null ? null : serviceNameN, - "categoryID": categoryId == null ? null : categoryId, - "categoryName": categoryName == null ? null : categoryName, - "serviceStatus": serviceStatus == null ? null : serviceStatus, - }; -} diff --git a/lib/models/profile/categroy.dart b/lib/models/profile/categroy.dart index df38b64..0c7bf26 100644 --- a/lib/models/profile/categroy.dart +++ b/lib/models/profile/categroy.dart @@ -6,6 +6,7 @@ import 'dart:convert'; import 'package:equatable/equatable.dart'; import 'package:mc_common_app/models/model/provider_model.dart'; +import 'package:mc_common_app/models/services/service_model.dart'; Category categoryFromJson(String str) => Category.fromJson(json.decode(str)); @@ -24,16 +25,14 @@ class Category { int? messageStatus; String? message; - factory Category.fromJson(Map json) => - Category( + factory Category.fromJson(Map json) => Category( totalItemsCount: json["totalItemsCount"] == null ? null : json["totalItemsCount"], data: json["data"] == null ? null : List.from(json["data"].map((x) => CategoryData.fromJson(x))), messageStatus: json["messageStatus"] == null ? null : json["messageStatus"], message: json["message"] == null ? null : json["message"], ); - Map toJson() => - { + Map toJson() => { "totalItemsCount": totalItemsCount == null ? null : totalItemsCount, "data": data == null ? null : List.from(data!.map((x) => x.toJson())), "messageStatus": messageStatus == null ? null : messageStatus, @@ -61,10 +60,9 @@ class CategoryData extends Equatable { dynamic? serviceCategoryImageUrl; String? branchId; String? branchName; - List? services; + List? services; - factory CategoryData.fromJson(Map json) => - CategoryData( + factory CategoryData.fromJson(Map json) => CategoryData( id: json["id"] == null ? null : json["id"], categoryName: json["categoryName"] == null ? null : json["categoryName"], categoryNameN: json["categoryNameN"] == null ? null : json["categoryNameN"], @@ -73,8 +71,7 @@ class CategoryData extends Equatable { services: [], ); - Map toJson() => - { + Map toJson() => { "id": id == null ? null : id, "categoryName": categoryName == null ? null : categoryName, "categoryNameN": categoryNameN == null ? null : categoryNameN, diff --git a/lib/models/services/branch_model.dart b/lib/models/services/branch_model.dart index 403cdc3..df56c35 100644 --- a/lib/models/services/branch_model.dart +++ b/lib/models/services/branch_model.dart @@ -1,5 +1,4 @@ - - +import 'package:mc_common_app/models/profile/categroy.dart'; import 'package:mc_common_app/models/services/service_model.dart'; class BranchModel { @@ -18,6 +17,8 @@ class BranchModel { final int? status; final dynamic statusText; final List? branchServices; + List? categories; + bool isExpanded; BranchModel({ this.id, @@ -35,6 +36,8 @@ class BranchModel { this.status, this.statusText, this.branchServices, + this.categories, + required this.isExpanded, }); factory BranchModel.fromJson(Map json) => BranchModel( @@ -52,7 +55,9 @@ class BranchModel { closeTime: json["closeTime"], status: json["status"], statusText: json["statusText"], - branchServices: json["branchServices"] == null ? [] : List.from(json["branchServices"]!.map((x) => ServiceModel.fromJson(x))), + branchServices: json["serviceProviderServices"] == null ? [] : List.from(json["serviceProviderServices"]!.map((x) => ServiceModel.fromJson(x))), + categories: [], + isExpanded: false, ); Map toJson() => { @@ -70,6 +75,6 @@ class BranchModel { "closeTime": closeTime, "status": status, "statusText": statusText, - "branchServices": branchServices == null ? [] : List.from(branchServices!.map((x) => x.toJson())), + "serviceProviderServices": branchServices == null ? [] : List.from(branchServices!.map((x) => x.toJson())), }; } diff --git a/lib/models/services/service_model.dart b/lib/models/services/service_model.dart index 82ed8fe..b11918c 100644 --- a/lib/models/services/service_model.dart +++ b/lib/models/services/service_model.dart @@ -1,61 +1,70 @@ -//TODO: this needs to match with ServiceProviderService from backend side class ServiceModel { - final int? providerBranchServiceId; + final int? serviceProviderServiceId; final dynamic providerServiceDescription; - final int? serviceCategoryId; + final int? categoryId; + final String? categoryName; final int? serviceId; final String? serviceDescription; final String? serviceDescriptionN; - final int? status; + final int? serviceStatus; final dynamic statusText; final bool? isAllowAppointment; + final bool? isAllowAppointmentHome; final int? customerLocationRange; + final String? rangePricePerKm; final int? itemsCount; bool isExpanded; ServiceModel({ - this.providerBranchServiceId, + this.serviceProviderServiceId, this.providerServiceDescription, - this.serviceCategoryId, + this.categoryId, + this.categoryName, this.serviceId, this.serviceDescription, this.serviceDescriptionN, - this.status, + this.serviceStatus, this.statusText, this.isAllowAppointment, + this.isAllowAppointmentHome, this.customerLocationRange, + this.rangePricePerKm, this.itemsCount, required this.isExpanded, }); - factory ServiceModel.fromJson(Map json) => - ServiceModel( - providerBranchServiceId: json["providerBranchServiceID"], + factory ServiceModel.fromJson(Map json) => ServiceModel( + serviceProviderServiceId: json["serviceProviderServiceID"], providerServiceDescription: json["providerServiceDescription"], - serviceCategoryId: json["serviceCategoryID"], + categoryId: json["categoryID"], + categoryName: json["categoryName"], serviceId: json["serviceID"], - serviceDescription: json["serviceDescription"], - serviceDescriptionN: json["serviceDescriptionN"], - status: json["status"], + serviceDescription: json["serviceDescription"] ?? json["serviceName"], + serviceDescriptionN: json["serviceDescriptionN"]?? json["serviceNameN"], + serviceStatus: json["serviceStatus"], statusText: json["statusText"], isAllowAppointment: json["isAllowAppointment"], + isAllowAppointmentHome: json["isAllowAppointmentHome"], customerLocationRange: json["customerLocationRange"], + rangePricePerKm: json["rangePricePerKm"].toString(), itemsCount: json["itemsCount"], isExpanded: false, ); - Map toJson() => - { - "providerBranchServiceID": providerBranchServiceId, + Map toJson() => { + "serviceProviderServiceID": serviceProviderServiceId, "providerServiceDescription": providerServiceDescription, - "serviceCategoryID": serviceCategoryId, + "categoryID": categoryId, + "categoryName": categoryName, "serviceID": serviceId, "serviceDescription": serviceDescription, "serviceDescriptionN": serviceDescriptionN, - "status": status, + "serviceStatus": serviceStatus, "statusText": statusText, "isAllowAppointment": isAllowAppointment, + "isAllowAppointmentHome": isAllowAppointmentHome, "customerLocationRange": customerLocationRange, + "rangePricePerKm": rangePricePerKm, "itemsCount": itemsCount, }; -} \ No newline at end of file +}