69 lines
1.9 KiB
Dart
69 lines
1.9 KiB
Dart
|
import 'package:parse_server_sdk_flutter/parse_server_sdk.dart';
|
||
|
|
||
|
class MealCategory {
|
||
|
late String? objectId;
|
||
|
late String value;
|
||
|
late String? notes;
|
||
|
|
||
|
MealCategory(ParseObject? object) {
|
||
|
if (object != null) {
|
||
|
objectId = object.get<String>('objectId');
|
||
|
value = object.get<String>('value')!;
|
||
|
notes = object.get<String>('notes');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<List<MealCategory>> fetchAll() async {
|
||
|
QueryBuilder<ParseObject> query =
|
||
|
QueryBuilder<ParseObject>(ParseObject('MealCategory'));
|
||
|
final ParseResponse apiResponse = await query.query();
|
||
|
|
||
|
if (apiResponse.success && apiResponse.results != null) {
|
||
|
return apiResponse.results!.map((e) => MealCategory(e as ParseObject)).toList();
|
||
|
} else {
|
||
|
return [];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<MealCategory?> get(String objectId) async {
|
||
|
QueryBuilder<ParseObject> query =
|
||
|
QueryBuilder<ParseObject>(ParseObject('MealCategory'))
|
||
|
..whereEqualTo('objectId', objectId);
|
||
|
final ParseResponse apiResponse = await query.query();
|
||
|
|
||
|
if (apiResponse.success && apiResponse.results != null) {
|
||
|
return MealCategory(apiResponse.result.first);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<void> save({
|
||
|
required String value,
|
||
|
String? notes,
|
||
|
}) async {
|
||
|
final mealCategory = ParseObject('MealCategory')
|
||
|
..set('value', value)
|
||
|
..set('notes', notes);
|
||
|
await mealCategory.save();
|
||
|
}
|
||
|
|
||
|
static Future<void> update(
|
||
|
String objectId, {
|
||
|
String? value,
|
||
|
String? notes,
|
||
|
}) async {
|
||
|
var mealCategory = ParseObject('MealCategory')..objectId = objectId;
|
||
|
if (value != null) {
|
||
|
mealCategory.set('value', value);
|
||
|
}
|
||
|
if (notes != null) {
|
||
|
mealCategory.set('notes', notes);
|
||
|
}
|
||
|
await mealCategory.save();
|
||
|
}
|
||
|
|
||
|
Future<void> delete() async {
|
||
|
var mealCategory = ParseObject('MealCategory')..objectId = objectId;
|
||
|
await mealCategory.delete();
|
||
|
}
|
||
|
}
|