Files
Nils-Johan Gynther d05b7da8bc
Test Suite / test (24.15.0) (push) Has been cancelled
feat: Add isPrivate field to AdminProduct and update filtering logic in admin panels
2026-05-11 19:30:42 +02:00

61 lines
1.8 KiB
Dart

class AdminProduct {
final int id;
final String name;
final String? canonicalName;
final String? normalizedName;
final int? ownerId;
final bool? isPrivate;
final int? categoryId;
final String? categoryPath;
final bool? isActive;
final String? status;
final DateTime? deletedAt;
const AdminProduct({
required this.id,
required this.name,
this.canonicalName,
this.normalizedName,
this.ownerId,
this.isPrivate,
this.categoryId,
this.categoryPath,
this.isActive,
this.status,
this.deletedAt,
});
String get displayName =>
canonicalName != null && canonicalName!.trim().isNotEmpty
? canonicalName!
: name;
factory AdminProduct.fromJson(Map<String, dynamic> json) {
final categoryRef = json['categoryRef'];
final names = <String>[];
dynamic current = 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 AdminProduct(
id: (json['id'] as num).toInt(),
name: (json['name'] ?? '').toString(),
canonicalName: json['canonicalName']?.toString(),
normalizedName: json['normalizedName']?.toString(),
ownerId: ((json['owner'] as Map<String, dynamic>?)?['id'] as num?)?.toInt(),
isPrivate: json['isPrivate'] as bool?,
categoryId: (json['categoryId'] as num?)?.toInt(),
categoryPath: names.isEmpty ? null : names.join(' > '),
isActive: json['isActive'] as bool?,
status: json['status']?.toString(),
deletedAt: json['deletedAt'] == null
? null
: DateTime.tryParse(json['deletedAt'].toString()),
);
}
}