Skip to content

Commit

Permalink
Merged branch develop into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Rogan committed Feb 18, 2017
2 parents 8337f3e + 89ae77b commit c011acc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

header("Access-Control-Allow-Origin: *");
$autoloader = require './vendor/autoload.php'; // Composer Autoload Libraries
$autoloader->add('', __DIR__ . '/generated-classes/'); // Propel ORM Classes
require './generated-conf/config.php'; // Propel Config
Expand Down
23 changes: 22 additions & 1 deletion api/routes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
$app->get('/category/all', function( $request, $response ) {
$q = new CategoryQuery;
$cats = $q::create()->find();





$response_json = [
"status" => [
"code" => $response->getStatusCode(),
Expand All @@ -15,9 +20,25 @@
"data" => []
];
foreach( $cats as $cat ) {

$q = new CategoryRankNutrientQuery;
$requestedCatRules = $q->filterByCategoryId($cat->getId())->find();
foreach($requestedCatRules as $rule) {
$rules[] = [
"nutrientName" => $rule->getNutrient()->getName(),
"nutrientId" => $rule->getNutrient()->getId(),
"operator" => $rule->getOperator(),
"threshold" => $rule->getThreshold(),
"units" => $rule->getUnits(),
"rank" => $rule->getRankId()
];
}


$response_json["data"][] = [
"id" => $cat->getId(),
"name" => $cat->getName()
"name" => $cat->getName(),
"rules" => $rules
];
}
$response = $response->withJSON($response_json);
Expand Down
54 changes: 53 additions & 1 deletion api/routes/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,59 @@
$newRule->setRankId($rank);
$newRule->setNutrientId($nutrient);

$newRule->save();
if($newRule->save()){
$msg = "New Rule Saved";
} else {
$msg = "There was an error saving this rule";
}



$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => [$msg]
]
];

$response = $response->withJSON($response_json);
return $response;


});

$app->post('/rules/updateRuleById/{ruleId}', function($request, $response) {

$rule = CategoryRankNutrientQuery::create()->findPk($request->getAttribute("ruleId"));

$cat = $request->getParam('catId');


$nutrient = $request->getParam('nutrientId');

$rank = $request->getParam('rankId');


$rule->setThreshold($request->getParam('threshold'));
$rule->setUnits($request->getParam('units'));
$rule->setOperator($request->getParam('operator'));
$rule->setCategoryId($cat);
$rule->setRankId($rank);
$rule->setNutrientId($nutrient);

if($rule->save()){
$msg = "Rule updated.";
} else {
$msg = "There was an error saving this rule";
}


$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => [$msg]
]
];
$response = $response->withJSON($response_json);
return $response;
});

0 comments on commit c011acc

Please sign in to comment.