Skip to content

Commit

Permalink
Merge branch 'joel' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
briankelleher committed Dec 7, 2016
2 parents 4459a36 + ba55b1c commit f98f816
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;
$config = [
'settings' => [
'displayErrorDetails' => true,
'addContentLengthHeader' => false
]
];

1 change: 1 addition & 0 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Routes
*/
require './routes/category.php';
require './routes/rules.php';

// Run App
$app->run();
26 changes: 26 additions & 0 deletions api/routes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@
"name" => $cat->getName()
];
}
$response = $response->withJSON($response_json);
return $response;
});

/**
* GET Category by ID
* @param id int PK of known category
*/

$app->get('/category/{id}', function( $request, $response ) {
$q = new CategoryQuery;
$cat = $q->findPK($request->getAttribute('id'));

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

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

$response = $response->withJSON($response_json);
return $response;
});
53 changes: 53 additions & 0 deletions api/routes/rules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

$app->get('/rules/byCategory/{id}', function($request, $response) {
$q = new CategoryRankNutrientQuery;
$requestedCatRules = $q->filterByCategoryId($request->getAttribute('id'))->find();

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

foreach($requestedCatRules as $rule) {
$response_json["data"][] = [
"nutrientName" => $rule->getNutrient()->getName(),
"nutrientId" => $rule->getNutrient()->getId(),
"operator" => $rule->getOperator(),
"threshold" => $rule->getThreshold(),
"units" => $rule->getUnits()
];
}

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



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

$newRule = new CategoryRankNutrient;

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


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

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


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

$newRule->save();


});

0 comments on commit f98f816

Please sign in to comment.