127 lines
3.7 KiB
Dart
127 lines
3.7 KiB
Dart
|
import 'package:parse_server_sdk_flutter/parse_server_sdk.dart';
|
||
|
|
||
|
class Accuracy {
|
||
|
late String? objectId;
|
||
|
late String value;
|
||
|
late bool forCarbsRatio = false;
|
||
|
late bool forPortionSize = false;
|
||
|
late int? confidenceRating;
|
||
|
late String? notes;
|
||
|
|
||
|
Accuracy(ParseObject? object) {
|
||
|
if (object != null) {
|
||
|
objectId = object.get<String>('objectId');
|
||
|
value = object.get<String>('value')!;
|
||
|
forCarbsRatio = object.get<bool>('forCarbsRatio')!;
|
||
|
forPortionSize = object.get<bool>('forPortionSize')!;
|
||
|
confidenceRating = object.get<num>('confidenceRating') != null
|
||
|
? object.get<num>('confidenceRating')!.toInt()
|
||
|
: null;
|
||
|
notes = object.get<String>('notes');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<List<Accuracy>> fetchAll() async {
|
||
|
QueryBuilder<ParseObject> query =
|
||
|
QueryBuilder<ParseObject>(ParseObject('Accuracy'));
|
||
|
final ParseResponse apiResponse = await query.query();
|
||
|
|
||
|
if (apiResponse.success && apiResponse.results != null) {
|
||
|
return apiResponse.results!
|
||
|
.map((e) => Accuracy(e as ParseObject))
|
||
|
.toList();
|
||
|
} else {
|
||
|
return [];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<List<Accuracy>> fetchAllForCarbsRatio() async {
|
||
|
QueryBuilder<ParseObject> query =
|
||
|
QueryBuilder<ParseObject>(ParseObject('Accuracy'))
|
||
|
..whereEqualTo('forCarbsRatio', true);
|
||
|
final ParseResponse apiResponse = await query.query();
|
||
|
|
||
|
if (apiResponse.success && apiResponse.results != null) {
|
||
|
return apiResponse.results!
|
||
|
.map((e) => Accuracy(e as ParseObject))
|
||
|
.toList();
|
||
|
} else {
|
||
|
return [];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<List<Accuracy>> fetchAllForPortionSize() async {
|
||
|
QueryBuilder<ParseObject> query =
|
||
|
QueryBuilder<ParseObject>(ParseObject('Accuracy'))
|
||
|
..whereEqualTo('forPortionSize', true);
|
||
|
final ParseResponse apiResponse = await query.query();
|
||
|
|
||
|
if (apiResponse.success && apiResponse.results != null) {
|
||
|
return apiResponse.results!
|
||
|
.map((e) => Accuracy(e as ParseObject))
|
||
|
.toList();
|
||
|
} else {
|
||
|
return [];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<Accuracy?> get(String objectId) async {
|
||
|
QueryBuilder<ParseObject> query =
|
||
|
QueryBuilder<ParseObject>(ParseObject('Accuracy'))
|
||
|
..whereEqualTo('objectId', objectId);
|
||
|
final ParseResponse apiResponse = await query.query();
|
||
|
|
||
|
if (apiResponse.success && apiResponse.results != null) {
|
||
|
return Accuracy(apiResponse.result.first);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<void> save({
|
||
|
required String value,
|
||
|
bool forCarbsRatio = false,
|
||
|
bool forPortionSize = false,
|
||
|
int? confidenceRating,
|
||
|
String? notes,
|
||
|
}) async {
|
||
|
final accuracy = ParseObject('Accuracy')
|
||
|
..set('value', value)
|
||
|
..set('forCarbsRatio', forCarbsRatio)
|
||
|
..set('forPortionSize', forPortionSize)
|
||
|
..set('confidenceRating', confidenceRating)
|
||
|
..set('notes', notes);
|
||
|
await accuracy.save();
|
||
|
}
|
||
|
|
||
|
static Future<void> update(
|
||
|
String objectId, {
|
||
|
String? value,
|
||
|
bool? forCarbsRatio,
|
||
|
bool? forPortionSize,
|
||
|
int? confidenceRating,
|
||
|
String? notes,
|
||
|
}) async {
|
||
|
var accuracy = ParseObject('Accuracy')..objectId = objectId;
|
||
|
if (value != null) {
|
||
|
accuracy.set('value', value);
|
||
|
}
|
||
|
if (forCarbsRatio != null) {
|
||
|
accuracy.set('forCarbsRatio', forCarbsRatio);
|
||
|
}
|
||
|
if (forPortionSize != null) {
|
||
|
accuracy.set('forPortionSize', forPortionSize);
|
||
|
}
|
||
|
if (confidenceRating != null) {
|
||
|
accuracy.set('confidenceRating', confidenceRating);
|
||
|
}
|
||
|
if (notes != null) {
|
||
|
accuracy.set('notes', notes);
|
||
|
}
|
||
|
await accuracy.save();
|
||
|
}
|
||
|
|
||
|
Future<void> delete() async {
|
||
|
var accuracy = ParseObject('Accuracy')..objectId = objectId;
|
||
|
await accuracy.delete();
|
||
|
}
|
||
|
}
|