pd-android-app/lib/models/product_mannual_model.dart
saritabirare 545637e035 1)product manual api integration
2)order management implementation
2024-09-16 16:48:52 +05:30

121 lines
3.1 KiB
Dart

class ProductManualModel {
final String id;
final String title;
final ProductManualDetails productManual;
final String createdAt;
final String updatedAt;
ProductManualModel({
required this.id,
required this.title,
required this.productManual,
required this.createdAt,
required this.updatedAt,
});
// Factory method to create a ProductManualModel from JSON
factory ProductManualModel.fromJson(Map<String, dynamic> json) {
return ProductManualModel(
id: json['_id'] ?? '',
title: json['title'] ?? '',
productManual: ProductManualDetails.fromJson(json['product_manual']),
createdAt: json['createdAt'],
updatedAt: json['updatedAt'],
);
}
// Method to convert a ProductManualModel to JSON
Map<String, dynamic> toJson() {
return {
'_id': id,
'title': title,
'product_manual': productManual.toJson(),
'createdAt': createdAt,
'updatedAt': updatedAt,
};
}
// Override toString for better debugging
@override
String toString() {
return 'ProductManualModel(id: $id, title: $title, productManual: $productManual, createdAt: $createdAt, updatedAt: $updatedAt)';
}
}
class ProductManualDetails {
final String publicId;
final String url;
final String filename;
ProductManualDetails({
required this.publicId,
required this.url,
required this.filename,
});
// Factory method to create ProductManualDetails from JSON
factory ProductManualDetails.fromJson(Map<String, dynamic> json) {
return ProductManualDetails(
publicId: json['public_id'] ?? '',
url: json['url'] ?? '',
filename: json['filename'] ?? '',
);
}
// Method to convert ProductManualDetails to JSON
Map<String, dynamic> toJson() {
return {
'public_id': publicId,
'url': url,
'filename': filename,
};
}
// Override toString for better debugging
@override
String toString() {
return 'ProductManualDetails(publicId: $publicId, url: $url, filename: $filename)';
}
}
// Model for handling the entire response
class ProductManualResponse {
final bool success;
final List<ProductManualModel> productManuals;
final int total;
ProductManualResponse({
required this.success,
required this.productManuals,
required this.total,
});
// Factory method to create ProductManualResponse from JSON
factory ProductManualResponse.fromJson(Map<String, dynamic> json) {
var productList = (json['productManuals'] as List)
.map((manual) => ProductManualModel.fromJson(manual))
.toList();
return ProductManualResponse(
success: json['success'] ?? false,
productManuals: productList,
total: json['total'] ?? 0,
);
}
// Method to convert ProductManualResponse to JSON
Map<String, dynamic> toJson() {
return {
'success': success,
'productManuals': productManuals.map((manual) => manual.toJson()).toList(),
'total': total,
};
}
// Override toString for better debugging
@override
String toString() {
return 'ProductManualResponse(success: $success, total: $total, productManuals: $productManuals)';
}
}