taafee-mobile/lib/features/card/data_layer/model/card_model.dart
2023-11-21 16:18:58 +03:00

80 lines
2.2 KiB
Dart

import 'package:taafee_mobile/features/card/data_layer/model/work_schedules.dart';
import 'package:taafee_mobile/features/home/data_layer/model/city.dart';
import 'card_images.dart';
import '../../../auth/data_layer/model/user.dart';
class CardModel {
int id;
String name;
CityModel cityModel;
String? address;
String? postalCode;
String phoneNumber;
String services;
int categoryId;
User user;
String website;
String additionalData;
List<CardImages> cardImages;
bool isFav;
int price;
String lat;
String lan;
WorkScheduleModel? workScheduleModel;
int avgRating;
CardModel(
{required this.id,
required this.name,
required this.cityModel,
this.address,
this.postalCode,
required this.phoneNumber,
required this.services,
required this.categoryId,
required this.user,
required this.website,
required this.additionalData,
required this.cardImages,
required this.isFav,
required this.price,
required this.lat,
required this.lan,
this.workScheduleModel,
required this.avgRating});
factory CardModel.fromJson(Map<String, dynamic> json) => CardModel(
id: json["id"],
name: json["name"],
cityModel: CityModel.fromJson(json["city"]),
address: json["address"],
postalCode: json["postal_code"],
phoneNumber: json["phone_number1"],
services: json["services"],
categoryId: json["category_id"] ?? json['category']['id'],
user: User.fromJson(json["user"]),
website: json["website"],
additionalData: json["additional_data"],
cardImages: CardImages.fromJsonList(json),
isFav: json["isFav"] == 1 ? true : false,
price: json["price"],
lan: json["lan"],
lat: json["lat"],
workScheduleModel: json["work_schedules"] == null ? null : WorkScheduleModel.fromJson(json),
avgRating: json["avg_rating"],
);
static List<CardModel> fromJsonList(Map<String, dynamic> json) {
List<CardModel> cards = [];
// ignore: avoid_function_literals_in_foreach_calls
json["data"].forEach(
(element) => cards.add(
CardModel.fromJson(element),
),
);
return cards;
}
}