51 lines
1016 B
Dart
51 lines
1016 B
Dart
class Category {
|
|
final int id;
|
|
final String name;
|
|
final String type;
|
|
final int? parentId;
|
|
|
|
Category({
|
|
required this.id,
|
|
required this.name,
|
|
required this.type,
|
|
this.parentId,
|
|
});
|
|
|
|
factory Category.fromJson(Map<String, dynamic> json) {
|
|
return Category(
|
|
id: json['id'] as int,
|
|
name: json['name'] as String,
|
|
type: json['type'] as String,
|
|
parentId: json['parent_id'] as int?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'type': type,
|
|
'parent_id': parentId,
|
|
};
|
|
}
|
|
|
|
Map<String, dynamic> toDbMap() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'type': type,
|
|
'parent_id': parentId,
|
|
'updated_at': DateTime.now().toIso8601String(),
|
|
};
|
|
}
|
|
|
|
factory Category.fromDbMap(Map<String, dynamic> map) {
|
|
return Category(
|
|
id: map['id'] as int,
|
|
name: map['name'] as String,
|
|
type: map['type'] as String,
|
|
parentId: map['parent_id'] as int?,
|
|
);
|
|
}
|
|
}
|