From d4b51ee92e991a705f786eb230425f5896286394 Mon Sep 17 00:00:00 2001 From: cdricms <36056008+cdricms@users.noreply.github.com> Date: Sat, 30 Dec 2023 17:50:12 +0100 Subject: [PATCH] Added all the types; some of them will need to be fixed --- Sources/USDA/types/AbridgedFoodItem.swift | 12 +++++ Sources/USDA/types/AbridgedFoodNutrient.swift | 9 ++++ Sources/USDA/types/BrandedFoodItem.swift | 44 +++++++++++++++++++ Sources/USDA/types/DataType.swift | 6 +++ Sources/USDA/types/FoodAttribute.swift | 6 +++ Sources/USDA/types/FoodAttributeType.swift | 5 +++ Sources/USDA/types/FoodCategory.swift | 5 +++ Sources/USDA/types/FoodComponent.swift | 10 +++++ Sources/USDA/types/FoodListCriteria.swift | 7 +++ Sources/USDA/types/FoodNutrient.swift | 13 ++++++ .../USDA/types/FoodNutrientDerivation.swift | 6 +++ Sources/USDA/types/FoodNutrientSource.swift | 5 +++ Sources/USDA/types/FoodPortion.swift | 11 +++++ Sources/USDA/types/FoodSearchCriteria.swift | 12 +++++ Sources/USDA/types/FoodUpdateLog.swift | 19 ++++++++ Sources/USDA/types/FoodsCriteria.swift | 9 ++++ Sources/USDA/types/InputFoodFoundation.swift | 5 +++ Sources/USDA/types/InputFoodSurvey.swift | 15 +++++++ Sources/USDA/types/MeasureUnit.swift | 5 +++ Sources/USDA/types/Nutrient.swift | 8 ++++ .../types/NutrientAcquisitionDetails.swift | 6 +++ .../USDA/types/NutrientAnalysisDetails.swift | 10 +++++ .../types/NutrientConversionFactors.swift | 5 +++ Sources/USDA/types/RetentionFactor.swift | 5 +++ Sources/USDA/types/SampleFoodItem.swift | 8 ++++ Sources/USDA/types/SearchResult.swift | 7 +++ Sources/USDA/types/SearchResultFood.swift | 17 +++++++ Sources/USDA/types/SortBy.swift | 4 ++ Sources/USDA/types/SortOrder.swift | 4 ++ Sources/USDA/types/SurveyFoodItem.swift | 14 ++++++ Sources/USDA/types/TradeChannel.swift | 3 ++ Sources/USDA/types/WweiaFoodCategory.swift | 4 ++ 32 files changed, 299 insertions(+) create mode 100644 Sources/USDA/types/AbridgedFoodItem.swift create mode 100644 Sources/USDA/types/AbridgedFoodNutrient.swift create mode 100644 Sources/USDA/types/BrandedFoodItem.swift create mode 100644 Sources/USDA/types/DataType.swift create mode 100644 Sources/USDA/types/FoodAttribute.swift create mode 100644 Sources/USDA/types/FoodAttributeType.swift create mode 100644 Sources/USDA/types/FoodCategory.swift create mode 100644 Sources/USDA/types/FoodComponent.swift create mode 100644 Sources/USDA/types/FoodListCriteria.swift create mode 100644 Sources/USDA/types/FoodNutrient.swift create mode 100644 Sources/USDA/types/FoodNutrientDerivation.swift create mode 100644 Sources/USDA/types/FoodNutrientSource.swift create mode 100644 Sources/USDA/types/FoodPortion.swift create mode 100644 Sources/USDA/types/FoodSearchCriteria.swift create mode 100644 Sources/USDA/types/FoodUpdateLog.swift create mode 100644 Sources/USDA/types/FoodsCriteria.swift create mode 100644 Sources/USDA/types/InputFoodFoundation.swift create mode 100644 Sources/USDA/types/InputFoodSurvey.swift create mode 100644 Sources/USDA/types/MeasureUnit.swift create mode 100644 Sources/USDA/types/Nutrient.swift create mode 100644 Sources/USDA/types/NutrientAcquisitionDetails.swift create mode 100644 Sources/USDA/types/NutrientAnalysisDetails.swift create mode 100644 Sources/USDA/types/NutrientConversionFactors.swift create mode 100644 Sources/USDA/types/RetentionFactor.swift create mode 100644 Sources/USDA/types/SampleFoodItem.swift create mode 100644 Sources/USDA/types/SearchResult.swift create mode 100644 Sources/USDA/types/SearchResultFood.swift create mode 100644 Sources/USDA/types/SortBy.swift create mode 100644 Sources/USDA/types/SortOrder.swift create mode 100644 Sources/USDA/types/SurveyFoodItem.swift create mode 100644 Sources/USDA/types/TradeChannel.swift create mode 100644 Sources/USDA/types/WweiaFoodCategory.swift diff --git a/Sources/USDA/types/AbridgedFoodItem.swift b/Sources/USDA/types/AbridgedFoodItem.swift new file mode 100644 index 0000000..f9e5fde --- /dev/null +++ b/Sources/USDA/types/AbridgedFoodItem.swift @@ -0,0 +1,12 @@ +public struct AbridgedFoodItem: Codable { + public let dataType: String + public let description: String + public let fdcId: Int + public let foodNutrients: [AbridgedFoodNutrient] + public let publicationDate: String? + public let brandOwner: String? + public let gtinUpc: String? + public let ndbNumber: Int? + public let foodCode: String? +} + diff --git a/Sources/USDA/types/AbridgedFoodNutrient.swift b/Sources/USDA/types/AbridgedFoodNutrient.swift new file mode 100644 index 0000000..8418954 --- /dev/null +++ b/Sources/USDA/types/AbridgedFoodNutrient.swift @@ -0,0 +1,9 @@ +public struct AbridgedFoodNutrient: Codable { + public let number: Int + public let name: String + public let amount: Float + public let unitName: String + public let derivationCode: String + public let derivationDescription: String +} + diff --git a/Sources/USDA/types/BrandedFoodItem.swift b/Sources/USDA/types/BrandedFoodItem.swift new file mode 100644 index 0000000..dc45459 --- /dev/null +++ b/Sources/USDA/types/BrandedFoodItem.swift @@ -0,0 +1,44 @@ +public struct BrandedFoodItem: Codable { + public let fdcId: Int + public let availableDate: String? + public let brandOwner: String? + public let dataSource: String? + public let dataType: String + public let description: String + public let foodClass: String? + public let gtinUpc: String? + public let householdServingFullText: String? + public let ingredients: String? + public let modifiedDate: String? + public let publicationDate: String? + public let servingSize: Float? + public let servingSizeUnit: String? + public let preparationStateCode: String? + public let brandedFoodCategory: String? + public let tradeChannel: [String]? + public let gpcClassCode: Int? + public let foodNutrients: [Any]? + public let foodUpdateLog: [Any]? + public let labelNutrients: LabelNutrients? + + public struct LabelNutrients: Codable { + public let fat: Nutrient + public let saturatedFat: Nutrient + public let transFat: Nutrient + public let cholesterol: Nutrient + public let sodium: Nutrient + public let carbohydrates: Nutrient + public let fiber: Nutrient + public let sugars: Nutrient + public let protein: Nutrient + public let calcium: Nutrient + public let iron: Nutrient + public let potassium: Nutrient + public let calories: Nutrient + + public struct Nutrient: Codable { + public let value: Float + } + } +} + diff --git a/Sources/USDA/types/DataType.swift b/Sources/USDA/types/DataType.swift new file mode 100644 index 0000000..fcfb926 --- /dev/null +++ b/Sources/USDA/types/DataType.swift @@ -0,0 +1,6 @@ + +public enum DataType: String, Codable { + case Branded, Foundation + case SR_Legacy = "SR Legacy" + case Survey = "Survey (FNDDS)" +} diff --git a/Sources/USDA/types/FoodAttribute.swift b/Sources/USDA/types/FoodAttribute.swift new file mode 100644 index 0000000..ee42bfa --- /dev/null +++ b/Sources/USDA/types/FoodAttribute.swift @@ -0,0 +1,6 @@ +public struct FoodAttribute: Codable { + public let id: Int + public let sequenceNumber: Int + public let value: String + public let foodAttributeType: FoodAttributeType +} diff --git a/Sources/USDA/types/FoodAttributeType.swift b/Sources/USDA/types/FoodAttributeType.swift new file mode 100644 index 0000000..792fd8b --- /dev/null +++ b/Sources/USDA/types/FoodAttributeType.swift @@ -0,0 +1,5 @@ +public struct FoodAttributeType: Codable { + public let id: Int + public let name: String + public let description: String +} diff --git a/Sources/USDA/types/FoodCategory.swift b/Sources/USDA/types/FoodCategory.swift new file mode 100644 index 0000000..7cf08ac --- /dev/null +++ b/Sources/USDA/types/FoodCategory.swift @@ -0,0 +1,5 @@ +public struct FoodCategory: Codable { + public let id: Int + public let code: String + public let description: String +} diff --git a/Sources/USDA/types/FoodComponent.swift b/Sources/USDA/types/FoodComponent.swift new file mode 100644 index 0000000..4bb6720 --- /dev/null +++ b/Sources/USDA/types/FoodComponent.swift @@ -0,0 +1,10 @@ +public struct FoodComponent: Codable { + public let id: Int + public let name: String + public let dataPoints: Int + public let gramWeight: Float + public let isRefuse: Bool + public let minYearAcquired: Int + public let percentWeight: Float +} + diff --git a/Sources/USDA/types/FoodListCriteria.swift b/Sources/USDA/types/FoodListCriteria.swift new file mode 100644 index 0000000..4fdae64 --- /dev/null +++ b/Sources/USDA/types/FoodListCriteria.swift @@ -0,0 +1,7 @@ +public struct FoodListCriteria: Codable { + public let dataType: [DataType]? + public let pageSize: Int? // 1..=200, default 50 + public let pageNumber: Int? + public let sortBy: SortBy? + public let sortOrder: SortOrder? +} diff --git a/Sources/USDA/types/FoodNutrient.swift b/Sources/USDA/types/FoodNutrient.swift new file mode 100644 index 0000000..be0e8c8 --- /dev/null +++ b/Sources/USDA/types/FoodNutrient.swift @@ -0,0 +1,13 @@ +public struct FoodNutrient: Codable { + public let id: Int + public let amount: Float + public let dataPoints: Int + public let min: Float + public let max: Float + public let median: Float + public let type: String + public let nutrient: Nutrient + public let foodNutrientDerivation: FoodNutrientDerivation + public let nutrientAnalysisDetails: NutrientAnalysisDetails +} + diff --git a/Sources/USDA/types/FoodNutrientDerivation.swift b/Sources/USDA/types/FoodNutrientDerivation.swift new file mode 100644 index 0000000..3e7ed5e --- /dev/null +++ b/Sources/USDA/types/FoodNutrientDerivation.swift @@ -0,0 +1,6 @@ +public struct FoodNutrientDerivation: Codable { + public let id: Int + public let code: String + public let description: String + public let foodNutrientSource: FoodNutrientSource +} diff --git a/Sources/USDA/types/FoodNutrientSource.swift b/Sources/USDA/types/FoodNutrientSource.swift new file mode 100644 index 0000000..eae2e53 --- /dev/null +++ b/Sources/USDA/types/FoodNutrientSource.swift @@ -0,0 +1,5 @@ +public struct FoodNutrientSource: Codable { + public let id: Int + public let code: String + public let description: String +} diff --git a/Sources/USDA/types/FoodPortion.swift b/Sources/USDA/types/FoodPortion.swift new file mode 100644 index 0000000..c30f91a --- /dev/null +++ b/Sources/USDA/types/FoodPortion.swift @@ -0,0 +1,11 @@ +public struct FoodPortion: Codable { + public let id: Int + public let amount: Float + public let dataPoints: Int + public let gramWeight: Float + public let minYearAcquired: Int + public let modifier: String + public let portionDescription: String + public let sequenceNumber: Int + public let measureUnit: MeasureUnit +} diff --git a/Sources/USDA/types/FoodSearchCriteria.swift b/Sources/USDA/types/FoodSearchCriteria.swift new file mode 100644 index 0000000..14190db --- /dev/null +++ b/Sources/USDA/types/FoodSearchCriteria.swift @@ -0,0 +1,12 @@ +public struct FoodSearchCriteria: Codable { + public let query: String + public let dataType: DataType? + public let pageSize: Int? + public let pageNumber: Int? + public let sortBy: SortBy? + public let sortOrder: SortOrder? + public let brandOwner: String? + public let tradeChannel: [TradeChannel]? // Max items: 3 + public let startDate: String? // Format: YYYY-MM-DD + public let endDate: String? // Format: YYYY-MM-DD +} diff --git a/Sources/USDA/types/FoodUpdateLog.swift b/Sources/USDA/types/FoodUpdateLog.swift new file mode 100644 index 0000000..067759a --- /dev/null +++ b/Sources/USDA/types/FoodUpdateLog.swift @@ -0,0 +1,19 @@ +public struct FoodUpdateLog: Codable { + public let fdcId: Int + public let availableDate: String + public let brandOwner: String + public let dataSource: String + public let dataType: String + public let description: String + public let foodClass: String + public let gtinUpc: String + public let householdServingFullText: String + public let ingredients: String + public let modifiedDate: String + public let publicationDate: String + public let servingSize: Float + public let servingSizeUnit: String + public let brandedFoodCategory: String + public let changes: String + public let foodAttributes: [FoodAttribute] +} diff --git a/Sources/USDA/types/FoodsCriteria.swift b/Sources/USDA/types/FoodsCriteria.swift new file mode 100644 index 0000000..a93e73c --- /dev/null +++ b/Sources/USDA/types/FoodsCriteria.swift @@ -0,0 +1,9 @@ +public struct FoodsCriteria: Codable { + public let fdcIds: [Int] // Max : 20 items + public let format: [Format]? + public let nutrients: [Int]? // Max : 25 items + + public enum Format: String, Codable { + case abridged, full + } +} diff --git a/Sources/USDA/types/InputFoodFoundation.swift b/Sources/USDA/types/InputFoodFoundation.swift new file mode 100644 index 0000000..6cf26ba --- /dev/null +++ b/Sources/USDA/types/InputFoodFoundation.swift @@ -0,0 +1,5 @@ +public struct InputFoodFoundation: Codable { + public let id: Int + public let foodDescription: String + public let inputFood: SampleFoodItem +} diff --git a/Sources/USDA/types/InputFoodSurvey.swift b/Sources/USDA/types/InputFoodSurvey.swift new file mode 100644 index 0000000..c4b549a --- /dev/null +++ b/Sources/USDA/types/InputFoodSurvey.swift @@ -0,0 +1,15 @@ +public struct InputFoodSurvey: Codable { + public let id: Int + public let amount: Float + public let foodDescription: String + public let ingredientCode: Int + public let ingredientDescription: String + public let ingredientWeight: Float + public let portionCode: String + public let portionDescription: String + public let sequenceNumber: Int + public let surveyFlag: Int + public let unit: String + public let inputFood: SurveyFoodItem + public let retentionFactor: RetentionFactor +} diff --git a/Sources/USDA/types/MeasureUnit.swift b/Sources/USDA/types/MeasureUnit.swift new file mode 100644 index 0000000..1f242af --- /dev/null +++ b/Sources/USDA/types/MeasureUnit.swift @@ -0,0 +1,5 @@ +public struct MeasureUnit: Codable { + public let id: Int + public let abbreviation: String + public let name: String +} diff --git a/Sources/USDA/types/Nutrient.swift b/Sources/USDA/types/Nutrient.swift new file mode 100644 index 0000000..67beee2 --- /dev/null +++ b/Sources/USDA/types/Nutrient.swift @@ -0,0 +1,8 @@ +public struct Nutrient: Codable { + public let description: String + public let id: Int + public let number: String + public let name: String + public let rank: Int + public let unitName: String +} diff --git a/Sources/USDA/types/NutrientAcquisitionDetails.swift b/Sources/USDA/types/NutrientAcquisitionDetails.swift new file mode 100644 index 0000000..d4671af --- /dev/null +++ b/Sources/USDA/types/NutrientAcquisitionDetails.swift @@ -0,0 +1,6 @@ +public struct NutrientAcquisitionDetails: Codable { + public let sampleUnitId: Int + public let purchaseDate: String + public let storeCity: String + public let storeState: String +} diff --git a/Sources/USDA/types/NutrientAnalysisDetails.swift b/Sources/USDA/types/NutrientAnalysisDetails.swift new file mode 100644 index 0000000..c51245e --- /dev/null +++ b/Sources/USDA/types/NutrientAnalysisDetails.swift @@ -0,0 +1,10 @@ +public struct NutrientAnalysisDetails: Codable { + public let subSampleId: Int + public let amount: Float + public let nutrientId: Int + public let labMethodDescription: String + public let labMethodOriginalDescription: String + public let labMethodLink: String + public let labMethodTechnique: String + public let nutrientAcquisitionDetails: [NutrientAcquisitionDetails] +} diff --git a/Sources/USDA/types/NutrientConversionFactors.swift b/Sources/USDA/types/NutrientConversionFactors.swift new file mode 100644 index 0000000..937d119 --- /dev/null +++ b/Sources/USDA/types/NutrientConversionFactors.swift @@ -0,0 +1,5 @@ +public struct NutrientConversionFactors: Codable { + public let type: String + public let value: Float +} + diff --git a/Sources/USDA/types/RetentionFactor.swift b/Sources/USDA/types/RetentionFactor.swift new file mode 100644 index 0000000..2d18c7b --- /dev/null +++ b/Sources/USDA/types/RetentionFactor.swift @@ -0,0 +1,5 @@ +public struct RetentionFactor: Codable { + public let id: Int + public let code: Int + public let description: String +} diff --git a/Sources/USDA/types/SampleFoodItem.swift b/Sources/USDA/types/SampleFoodItem.swift new file mode 100644 index 0000000..278bf3d --- /dev/null +++ b/Sources/USDA/types/SampleFoodItem.swift @@ -0,0 +1,8 @@ +public struct SampleFoodItem: Codable { + public let fdcId: Int + public let dataType: String + public let description: String + public let foodClass: String + public let publicationDate: String + public let foodAttributes: [FoodCategory] +} diff --git a/Sources/USDA/types/SearchResult.swift b/Sources/USDA/types/SearchResult.swift new file mode 100644 index 0000000..6600899 --- /dev/null +++ b/Sources/USDA/types/SearchResult.swift @@ -0,0 +1,7 @@ +public struct SearchResult: Codable { + public let foodSearchCriteria: FoodSearchCriteria? + public let totalHits: Int? + public let currentPage: Int? + public let totalPages: Int? + public let foods: [SearchResultFood]? +} diff --git a/Sources/USDA/types/SearchResultFood.swift b/Sources/USDA/types/SearchResultFood.swift new file mode 100644 index 0000000..4775913 --- /dev/null +++ b/Sources/USDA/types/SearchResultFood.swift @@ -0,0 +1,17 @@ +public struct SearchResultFood: Codable { + public let fdcId: Int + public let dataType: String? + public let description: String + public let foodCode: String? + public let foodNutrients: [AbridgedFoodNutrient] + public let publicationDate: String? + public let scientificName: String? + public let brandOwner: String? + public let gtinUpc: String? + public let ingredients: String? + public let ndbNumber: Int? + public let additionalDescriptions: String? + public let allHighlightFields: String? + public let score: Float? +} + diff --git a/Sources/USDA/types/SortBy.swift b/Sources/USDA/types/SortBy.swift new file mode 100644 index 0000000..3886109 --- /dev/null +++ b/Sources/USDA/types/SortBy.swift @@ -0,0 +1,4 @@ + +public enum SortBy: String, Codable { + case dataType_keyword = "dataType.keyword", lowercaseDescription_keyword="lowercaseDescription.keyword", fdcId, publishedDate +} diff --git a/Sources/USDA/types/SortOrder.swift b/Sources/USDA/types/SortOrder.swift new file mode 100644 index 0000000..3c0d0e4 --- /dev/null +++ b/Sources/USDA/types/SortOrder.swift @@ -0,0 +1,4 @@ + +public enum SortOrder: String, Codable { + case asc, desc +} diff --git a/Sources/USDA/types/SurveyFoodItem.swift b/Sources/USDA/types/SurveyFoodItem.swift new file mode 100644 index 0000000..99edfc4 --- /dev/null +++ b/Sources/USDA/types/SurveyFoodItem.swift @@ -0,0 +1,14 @@ +public struct SurveyFoodItem: Codable { + public let fdcId: Int + public let dataType: String + public let description: String + public let endDate: String + public let foodClass: String + public let foodCode: String + public let publicationDate: String + public let startDate: String + public let foodAttributes: [FoodAttribute] + public let foodPortions: [FoodPortion] + // ... other properties for SurveyFoodItem + public let wweiaFoodCategory: WweiaFoodCategory +} diff --git a/Sources/USDA/types/TradeChannel.swift b/Sources/USDA/types/TradeChannel.swift new file mode 100644 index 0000000..57ff35a --- /dev/null +++ b/Sources/USDA/types/TradeChannel.swift @@ -0,0 +1,3 @@ +public enum TradeChannel: String, Codable { + case CHILD_NUTRITION_FOOD_PROGRAMS, DRUG, FOOD_SERVICE, GROCERY, MASS_MERCHANDISING, MILITARY, ONLINE, VENDING +} diff --git a/Sources/USDA/types/WweiaFoodCategory.swift b/Sources/USDA/types/WweiaFoodCategory.swift new file mode 100644 index 0000000..8ebe91b --- /dev/null +++ b/Sources/USDA/types/WweiaFoodCategory.swift @@ -0,0 +1,4 @@ +public struct WweiaFoodCategory: Codable { + public let wweiaFoodCategoryCode: Int + public let wweiaFoodCategoryDescription: String +}