From 846d90bfae7d26832aa33d881a06b0b82d8732f0 Mon Sep 17 00:00:00 2001 From: briankelleher Date: Tue, 6 Dec 2016 23:00:57 -0500 Subject: [PATCH] Get all Foods --- api/Foodbank.postman_collection.json | 16 ++++++++++- api/generated-conf/config.php | 2 +- api/index.php | 1 + api/propel.yml | 2 +- api/propel.yml.dist | 2 +- api/routes/food.php | 41 ++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 api/routes/food.php diff --git a/api/Foodbank.postman_collection.json b/api/Foodbank.postman_collection.json index 8a9179b..63dbc4c 100644 --- a/api/Foodbank.postman_collection.json +++ b/api/Foodbank.postman_collection.json @@ -2,7 +2,7 @@ "variables": [], "info": { "name": "Foodbank", - "_postman_id": "a8e172cf-8f6b-3abf-a0ee-90832eecb2bf", + "_postman_id": "e6744472-b14a-9307-0f99-b6b094259176", "description": "", "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" }, @@ -20,6 +20,20 @@ "description": "" }, "response": [] + }, + { + "name": "GET All Food", + "request": { + "url": "http://localhost:8000/food/all", + "method": "GET", + "header": [], + "body": { + "mode": "formdata", + "formdata": [] + }, + "description": "" + }, + "response": [] } ] } \ No newline at end of file diff --git a/api/generated-conf/config.php b/api/generated-conf/config.php index 30bb12d..6d7b92f 100644 --- a/api/generated-conf/config.php +++ b/api/generated-conf/config.php @@ -9,7 +9,7 @@ 'password' => 'foodbank123', 'settings' => array ( - 'charset' => 'utf8mb4_unicode_ci', + 'charset' => 'utf8', 'queries' => array ( ), diff --git a/api/index.php b/api/index.php index 3bae386..857907c 100644 --- a/api/index.php +++ b/api/index.php @@ -13,6 +13,7 @@ */ require './routes/category.php'; require './routes/rules.php'; +require './routes/food.php'; // Run App $app->run(); \ No newline at end of file diff --git a/api/propel.yml b/api/propel.yml index c305b3e..bcdf6b8 100644 --- a/api/propel.yml +++ b/api/propel.yml @@ -7,4 +7,4 @@ propel: user: foodbank password: foodbank123 settings: - charset: utf8mb4_unicode_ci + charset: utf8 diff --git a/api/propel.yml.dist b/api/propel.yml.dist index 567b5f9..6ab6c61 100644 --- a/api/propel.yml.dist +++ b/api/propel.yml.dist @@ -22,4 +22,4 @@ propel: # user: foodbank # password: # settings: -# charset: utf8mb4_unicode_ci +# charset: utf8 diff --git a/api/routes/food.php b/api/routes/food.php new file mode 100644 index 0000000..94194bb --- /dev/null +++ b/api/routes/food.php @@ -0,0 +1,41 @@ +get('/food/all', function( $request, $response ) { + $q = new FoodQuery(); + $foods = $q::create() + ->useRankQuery() + ->endUse() + ->useCategoryQuery() + ->endUse() + ->find(); + $response_json = [ + "status" => [ + "code" => $response->getStatusCode(), + "message" => "OK" + ], + "data" => [] + ]; + foreach( $foods as $food ) { + $rank = $food->getRank(); + $category = $food->getCategory(); + $response_json["data"][] = [ + "id" => $food->getId(), + "name" => $food->getName(), + "barcode" => $food->getBarcode(), + "rank" => [ + "id" => $food->getRankId(), + "name" => $rank->getName() + ], + "category" => [ + "id" => $food->getCategoryId(), + "name" => $category->getName() + ] + ]; + } + $response = $response->withJSON($response_json); + return $response; +}); \ No newline at end of file