60 lines
1.9 KiB
Dart
60 lines
1.9 KiB
Dart
class AdminInventoryItem {
|
|
final int id;
|
|
final int userId;
|
|
final String username;
|
|
final String userEmail;
|
|
final int productId;
|
|
final String productName;
|
|
final String? productCanonicalName;
|
|
final double quantity;
|
|
final String unit;
|
|
final String? location;
|
|
final String? brand;
|
|
final String? receiptName;
|
|
final String? suitableFor;
|
|
final String? comment;
|
|
|
|
const AdminInventoryItem({
|
|
required this.id,
|
|
required this.userId,
|
|
required this.username,
|
|
required this.userEmail,
|
|
required this.productId,
|
|
required this.productName,
|
|
this.productCanonicalName,
|
|
required this.quantity,
|
|
required this.unit,
|
|
this.location,
|
|
this.brand,
|
|
this.receiptName,
|
|
this.suitableFor,
|
|
this.comment,
|
|
});
|
|
|
|
String get displayName {
|
|
final canonical = productCanonicalName?.trim();
|
|
if (canonical != null && canonical.isNotEmpty) return canonical;
|
|
return productName;
|
|
}
|
|
|
|
factory AdminInventoryItem.fromJson(Map<String, dynamic> json) {
|
|
final user = (json['user'] as Map<String, dynamic>?) ?? const {};
|
|
final product = (json['product'] as Map<String, dynamic>?) ?? const {};
|
|
return AdminInventoryItem(
|
|
id: json['id'] as int,
|
|
userId: json['userId'] as int,
|
|
username: user['username'] as String? ?? '',
|
|
userEmail: user['email'] as String? ?? '',
|
|
productId: json['productId'] as int,
|
|
productName: product['name'] as String? ?? '',
|
|
productCanonicalName: product['canonicalName'] as String?,
|
|
quantity: double.tryParse(json['quantity']?.toString() ?? '0') ?? 0,
|
|
unit: json['unit'] as String? ?? '',
|
|
location: json['location'] as String?,
|
|
brand: json['brand'] as String?,
|
|
receiptName: json['receiptName'] as String?,
|
|
suitableFor: json['suitableFor'] as String?,
|
|
comment: json['comment'] as String?,
|
|
);
|
|
}
|
|
} |