From 7488ecd00b2d35511a454cadeee5322633c0d02e Mon Sep 17 00:00:00 2001 From: jsalisbury Date: Thu, 2 Mar 2017 20:35:00 -0500 Subject: [PATCH 1/4] reverting back --- api/routes/category.php | 22 ++++++++++++---------- api/routes/rules.php | 4 +++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/api/routes/category.php b/api/routes/category.php index 137363d..84a24cb 100644 --- a/api/routes/category.php +++ b/api/routes/category.php @@ -15,19 +15,21 @@ ], "data" => [] ]; - +//[strtolower($rule->getRank()->getName())][$rule->getNutrient()->getName()] foreach( $cats as $cat ) { $rules = []; $q = new CategoryRankNutrientQuery; - $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByRankId()->find(); + $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByNutrientId()->find(); foreach($requestedCatRules as $rule) { - $rules[$rule->getNutrient()->getName()][] = [ - "nutrientName" => $rule->getNutrient()->getName(), - "nutrientId" => $rule->getNutrient()->getId(), - "operator" => $rule->getOperator(), - "threshold" => $rule->getThreshold(), - "units" => $rule->getUnits(), - "rank" => $rule->getRankId() + $rules[] = [ + "ruleId" => $rule->getId(), + "nutrientName" => $rule->getNutrient()->getName(), + "nutrientId" => $rule->getNutrient()->getId(), + "operator" => $rule->getOperator(), + "threshold" => $rule->getThreshold(), + "units" => $rule->getUnits(), + "rank" => $rule->getRankId(), + "categoryId" => $rule->getCategoryId() ]; } @@ -35,7 +37,7 @@ $response_json["data"][] = [ "id" => $cat->getId(), "name" => $cat->getName(), - "rules" => $rules + "rules" => [$rules] ]; } diff --git a/api/routes/rules.php b/api/routes/rules.php index 0b81736..83b1d1e 100644 --- a/api/routes/rules.php +++ b/api/routes/rules.php @@ -14,12 +14,14 @@ foreach($requestedCatRules as $rule) { $response_json["data"][] = [ + "ruleId" => $rule->getId(), "nutrientName" => $rule->getNutrient()->getName(), "nutrientId" => $rule->getNutrient()->getId(), "operator" => $rule->getOperator(), "threshold" => $rule->getThreshold(), "units" => $rule->getUnits(), - "rank" => $rule->getRankId() + "rank" => $rule->getRankId(), + "categoryId" => $rule->getCategoryId() ]; } From 31d7ca0ea8510ba72dc6e88662987f4ac1c0c728 Mon Sep 17 00:00:00 2001 From: jsalisbury Date: Thu, 2 Mar 2017 21:09:39 -0500 Subject: [PATCH 2/4] nutrient all --- api/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/api/index.php b/api/index.php index 7475b8e..26a54b8 100644 --- a/api/index.php +++ b/api/index.php @@ -15,6 +15,7 @@ require './routes/rules.php'; require './routes/food.php'; require './routes/decision.php'; +require './routes/nutrient.php'; // Run App $app->run(); \ No newline at end of file From 72c265a4bcdc27ef4b01c59d4f4d04e7fa60a160 Mon Sep 17 00:00:00 2001 From: jsalisbury Date: Thu, 2 Mar 2017 21:45:49 -0500 Subject: [PATCH 3/4] decision now adds food namee on insert --- api/routes/decision.php | 1 + 1 file changed, 1 insertion(+) diff --git a/api/routes/decision.php b/api/routes/decision.php index 68bd951..14005aa 100644 --- a/api/routes/decision.php +++ b/api/routes/decision.php @@ -241,6 +241,7 @@ function getProductInfo($upc) { $newFood->setRankId($newFoodRank); $newFood->setCategoryId($newFoodCat); $newFood->setBarcode($barcode); + $newFood->setName($res["food"]['brand']." " .$res["food"]['name']); if($newFood->save()){ From 8ec2f9f527d3f17ee6c283119413de0a6bea191c Mon Sep 17 00:00:00 2001 From: jsalisbury Date: Thu, 2 Mar 2017 21:57:25 -0500 Subject: [PATCH 4/4] im a moron --- api/routes/nutrient.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 api/routes/nutrient.php diff --git a/api/routes/nutrient.php b/api/routes/nutrient.php new file mode 100644 index 0000000..2926551 --- /dev/null +++ b/api/routes/nutrient.php @@ -0,0 +1,25 @@ +get('/nutrient/all', function( $request, $response ) { + $q = new NutrientQuery; + $nuts = $q::create()->find(); + + $response_json = [ + "status" => [ + "code" => $response->getStatusCode(), + "message" => "OK" + ], + "data" => [] + ]; +//[strtolower($rule->getRank()->getName())][$rule->getNutrient()->getName()] + foreach( $nuts as $nut ) { + $response_json["data"][] = [ + "id" => $nut->getId(), + "name" => $nut->getName(), + ]; + + } + + $response = $response->withJSON($response_json); + return $response; + +}); \ No newline at end of file