toJson method

  1. @override
Map<String, dynamic> toJson()
override

Converts the BaseDTO to a JSON object.

This method can be used when making HTTP requests to convert the DTO to a format that can be sent in the request.

Implementation

@override
Map<String, dynamic> toJson() {
  final Map<String, dynamic> data = super.toJson();

  data['title'] = title;
  data['highlightRate'] = highlightRate;
  data['slug'] = slug;
  data['link'] = link;
  data['description'] = description;
  data['discountStartDate'] = discountStartDate;
  data['discountEndDate'] = discountEndDate;
  data['limit'] = limit;
  data['used'] = used;
  data['showOnMain'] = showOnMain;
  data['type'] = type;
  data['priceType'] = priceType;
  data['productCount'] = productCount;
  data['freeProductCount'] = freeProductCount;
  if (products != null) {
    data['products'] = products!.map((v) => v.toJson()).toList();
  }
  if (categories != null) {
    data['categories'] = categories!.map((v) => v.toJson()).toList();
  }
  if (brands != null) {
    data['brands'] = brands!.map((v) => v.toJson()).toList();
  }
  if (tags != null) {
    data['tags'] = tags!.map((v) => v.toJson()).toList();
  }
  if (photo != null) {
    data['photo'] = photo!.toJson();
  }
  return data;
}