Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…/foodbank into develop
  • Loading branch information
Timothy Morris committed Mar 6, 2017
2 parents 8a5462b + 8ec2f9f commit 9cde9d1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require './routes/rules.php';
require './routes/food.php';
require './routes/decision.php';
require './routes/nutrient.php';

// Run App
$app->run();
22 changes: 12 additions & 10 deletions api/routes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@
],
"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()
];
}


$response_json["data"][] = [
"id" => $cat->getId(),
"name" => $cat->getName(),
"rules" => $rules
"rules" => [$rules]
];

}
Expand Down
1 change: 1 addition & 0 deletions api/routes/decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()){
Expand Down
25 changes: 25 additions & 0 deletions api/routes/nutrient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$app->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;

});
4 changes: 3 additions & 1 deletion api/routes/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
];
}

Expand Down

0 comments on commit 9cde9d1

Please sign in to comment.