Skip to content

Commit

Permalink
Get all Foods
Browse files Browse the repository at this point in the history
  • Loading branch information
briankelleher committed Dec 7, 2016
1 parent c9d378a commit 846d90b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
16 changes: 15 additions & 1 deletion api/Foodbank.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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": []
}
]
}
2 changes: 1 addition & 1 deletion api/generated-conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'password' => 'foodbank123',
'settings' =>
array (
'charset' => 'utf8mb4_unicode_ci',
'charset' => 'utf8',
'queries' =>
array (
),
Expand Down
1 change: 1 addition & 0 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
require './routes/category.php';
require './routes/rules.php';
require './routes/food.php';

// Run App
$app->run();
2 changes: 1 addition & 1 deletion api/propel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ propel:
user: foodbank
password: foodbank123
settings:
charset: utf8mb4_unicode_ci
charset: utf8
2 changes: 1 addition & 1 deletion api/propel.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ propel:
# user: foodbank
# password:
# settings:
# charset: utf8mb4_unicode_ci
# charset: utf8
41 changes: 41 additions & 0 deletions api/routes/food.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* GET All Food
* No Parameters
*/
$app->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;
});

0 comments on commit 846d90b

Please sign in to comment.