feat: Implement admin pantry item management with create and update functionality, including category selection and validation
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-11 11:18:13 +02:00
parent 573c12cdc3
commit f132983b75
11 changed files with 683 additions and 38 deletions
@@ -6,6 +6,8 @@ class AdminPantryItem {
final int productId;
final String productName;
final String? productCanonicalName;
final int? categoryId;
final String? categoryPath;
final String? location;
const AdminPantryItem({
@@ -16,6 +18,8 @@ class AdminPantryItem {
required this.productId,
required this.productName,
this.productCanonicalName,
this.categoryId,
this.categoryPath,
this.location,
});
@@ -28,6 +32,15 @@ class AdminPantryItem {
factory AdminPantryItem.fromJson(Map<String, dynamic> json) {
final user = (json['user'] as Map<String, dynamic>?) ?? const {};
final product = (json['product'] as Map<String, dynamic>?) ?? const {};
final names = <String>[];
dynamic current = product['categoryRef'];
while (current is Map<String, dynamic>) {
final name = current['name']?.toString().trim();
if (name != null && name.isNotEmpty) {
names.insert(0, name);
}
current = current['parent'];
}
return AdminPantryItem(
id: (json['id'] as num).toInt(),
userId: (json['userId'] as num).toInt(),
@@ -36,6 +49,8 @@ class AdminPantryItem {
productId: (json['productId'] as num).toInt(),
productName: product['name'] as String? ?? '',
productCanonicalName: product['canonicalName'] as String?,
categoryId: (product['categoryId'] as num?)?.toInt(),
categoryPath: names.isEmpty ? null : names.join(' > '),
location: json['location'] as String?,
);
}