Editable search data collections

This commit is contained in:
2024-08-15 20:10:07 +08:00
parent 09e904f52f
commit 403639088f
12 changed files with 439 additions and 184 deletions

View File

@ -98,7 +98,7 @@ class Nutrients {
}
class FoodSearchCriteria {
List<Type?> dataType;
List<FoodType?> dataType;
String query;
String generalSearchInput;
int pageNumber;
@ -107,7 +107,7 @@ class FoodSearchCriteria {
int numberOfResultsPerPage;
int pageSize;
bool requireAllWords;
List<Type?> foodTypes;
List<FoodType?> foodTypes;
FoodSearchCriteria({
required this.dataType,
@ -124,7 +124,7 @@ class FoodSearchCriteria {
factory FoodSearchCriteria.fromJson(Map<String, dynamic> json) =>
FoodSearchCriteria(
dataType: List<Type>.from(
dataType: List<FoodType?>.from(
json["dataType"]?.map((x) => typeValues.map[x]) ?? List.empty()),
query: json["query"],
generalSearchInput: json["generalSearchInput"],
@ -134,7 +134,7 @@ class FoodSearchCriteria {
numberOfResultsPerPage: json["numberOfResultsPerPage"],
pageSize: json["pageSize"],
requireAllWords: json["requireAllWords"],
foodTypes: List<Type>.from(
foodTypes: List<FoodType>.from(
json["foodTypes"]?.map((x) => typeValues.map[x]) ?? List.empty()),
);
@ -154,20 +154,20 @@ class FoodSearchCriteria {
};
}
enum Type { FOUNDATION, SR_LEGACY }
enum FoodType { FOUNDATION, SR_LEGACY }
final typeValues =
EnumValues({"Foundation": Type.FOUNDATION, "SR Legacy": Type.SR_LEGACY});
final typeValues = EnumValues(
{"Foundation": FoodType.FOUNDATION, "SR Legacy": FoodType.SR_LEGACY});
class FoodData {
int fdcId;
String description;
String? commonNames;
String? additionalDescriptions;
Type? dataType;
FoodType? dataType;
int? ndbNumber;
DateTime publishedDate;
FoodCategory? foodCategory;
String? foodCategory;
DateTime? mostRecentAcquisitionDate;
String allHighlightFields;
double score;
@ -208,7 +208,7 @@ class FoodData {
dataType: typeValues.map[json["dataType"]],
ndbNumber: json["ndbNumber"],
publishedDate: DateTime.parse(json["publishedDate"]),
foodCategory: foodCategoryValues.map[json["foodCategory"]],
foodCategory: json["foodCategory"],
mostRecentAcquisitionDate: json["mostRecentAcquisitionDate"] == null
? null
: DateTime.parse(json["mostRecentAcquisitionDate"]),
@ -237,7 +237,7 @@ class FoodData {
"ndbNumber": ndbNumber,
"publishedDate":
"${publishedDate.year.toString().padLeft(4, '0')}-${publishedDate.month.toString().padLeft(2, '0')}-${publishedDate.day.toString().padLeft(2, '0')}",
"foodCategory": foodCategoryValues.reverse[foodCategory],
"foodCategory": foodCategory,
"mostRecentAcquisitionDate":
"${mostRecentAcquisitionDate!.year.toString().padLeft(4, '0')}-${mostRecentAcquisitionDate!.month.toString().padLeft(2, '0')}-${mostRecentAcquisitionDate!.day.toString().padLeft(2, '0')}",
"allHighlightFields": allHighlightFields,
@ -255,11 +255,6 @@ class FoodData {
};
}
enum FoodCategory { DAIRY_AND_EGG_PRODUCTS }
final foodCategoryValues =
EnumValues({"Dairy and Egg Products": FoodCategory.DAIRY_AND_EGG_PRODUCTS});
class FoodNutrient {
int nutrientId;
String nutrientName;