2021-11-07 20:13:28 +00:00
|
|
|
import 'package:diameter/main.dart';
|
|
|
|
import 'package:objectbox/objectbox.dart';
|
2022-03-21 00:07:29 +00:00
|
|
|
import 'package:diameter/objectbox.g.dart' show MealCategory_;
|
2021-10-22 23:08:09 +00:00
|
|
|
|
2022-03-21 00:07:29 +00:00
|
|
|
@Entity(uid: 3158200688796904913)
|
|
|
|
@Sync()
|
2021-10-22 23:08:09 +00:00
|
|
|
class MealCategory {
|
2021-11-07 20:13:28 +00:00
|
|
|
static final Box<MealCategory> box = objectBox.store.box<MealCategory>();
|
|
|
|
|
2022-03-21 00:07:29 +00:00
|
|
|
// properties
|
2021-11-07 20:13:28 +00:00
|
|
|
int id;
|
2022-03-21 00:07:29 +00:00
|
|
|
bool deleted;
|
2022-07-08 02:08:50 +00:00
|
|
|
@Unique()
|
2021-11-07 20:13:28 +00:00
|
|
|
String value;
|
|
|
|
String? notes;
|
2022-07-08 02:08:50 +00:00
|
|
|
String? source;
|
2021-11-07 20:13:28 +00:00
|
|
|
|
2022-03-21 00:07:29 +00:00
|
|
|
// constructor
|
2021-11-07 20:13:28 +00:00
|
|
|
MealCategory({
|
|
|
|
this.id = 0,
|
2022-03-21 00:07:29 +00:00
|
|
|
this.deleted = false,
|
2021-11-07 20:13:28 +00:00
|
|
|
this.value = '',
|
|
|
|
this.notes,
|
2022-07-08 02:08:50 +00:00
|
|
|
this.source,
|
2021-11-07 20:13:28 +00:00
|
|
|
});
|
|
|
|
|
2022-03-21 00:07:29 +00:00
|
|
|
// methods
|
2021-11-07 20:13:28 +00:00
|
|
|
static MealCategory? get(int id) => box.get(id);
|
|
|
|
static void put(MealCategory mealCategory) => box.put(mealCategory);
|
2022-03-21 00:07:29 +00:00
|
|
|
|
|
|
|
static List<MealCategory> getAll() {
|
|
|
|
QueryBuilder<MealCategory> builder = box.query(MealCategory_.deleted.equals(false))..order(MealCategory_.value);
|
|
|
|
return builder.build().find();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove(int id) {
|
|
|
|
final item = box.get(id);
|
|
|
|
if (item != null) {
|
|
|
|
item.deleted = true;
|
|
|
|
box.put(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return value;
|
|
|
|
}
|
2022-07-08 02:08:50 +00:00
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
|
|
data['id'] = id;
|
|
|
|
data['deleted'] = deleted;
|
|
|
|
data['value'] = value;
|
|
|
|
data['notes'] = notes;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static String? putFromJson(
|
|
|
|
Map<String, dynamic> json, bool overrideExisting, String? source) {
|
|
|
|
final mealCategory = MealCategory(
|
|
|
|
id: overrideExisting ? json['id'] : 0,
|
|
|
|
deleted: json['deleted'] == 'true',
|
|
|
|
value: json['value'],
|
|
|
|
notes: json['notes'],
|
|
|
|
source: source,
|
|
|
|
);
|
|
|
|
|
|
|
|
MealCategory.put(mealCategory);
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|