Skip to content

Commit

Permalink
mock decision return
Browse files Browse the repository at this point in the history
  • Loading branch information
briankelleher committed Dec 12, 2016
1 parent bf45658 commit 8ce89f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require './routes/category.php';
require './routes/rules.php';
require './routes/food.php';
require './routes/decision.php';

// Run App
$app->run();
30 changes: 30 additions & 0 deletions api/routes/decision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* POST Request for food decision
* @param barcode Food Barcode
* @param category Food Category
*/
$app->post('/decision', function($request, $response) {
$formDataArray = $request->getParsedBody();
$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => "OK"
],
"data" => $formDataArray
];
// Some Decision Logic
$random = rand(0,2);
$rank = "";
if ( $random === 0 ) {
$rank = "Green";
} else if ( $random === 1 ) {
$rank = "Yellow";
} else {
$rank = "Red";
}
$response_json["decision"] = $rank;
$response = $response->withJSON($response_json);
return $response;
});

0 comments on commit 8ce89f7

Please sign in to comment.