diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 1e7105a..91f4eed 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -13,31 +13,36 @@ class ItemController extends Controller return response()->json(Item::all()); } - public function searchAllItems() + public function showByEvent($event) { - return response()->json(Item::all()); //TODO actually search + return response()->json(Item::byEvent($event)); } - public function showOneItem($id) + public function searchByEvent($event, $query) + { + return response()->json(Item::byEvent($event)); //TODO actually search + } + + public function showOneItem($event, $id) { return response()->json(Item::find($id)); } - public function create(Request $request) + public function create($event, Request $request) { $item = Item::create($request->all()); return response()->json($item, 201); } - public function update($id, Request $request) + public function update($event, $id, Request $request) { $item = Item::findOrFail($id); $item->update($request->all()); - return response()->json($item, 200); + return response()->json($event, $item, 200); } - public function delete($id) + public function delete($event, $id) { Item::findOrFail($id)->delete(); return response('Deleted Successfully', 200); diff --git a/app/Item.php b/app/Item.php index 23324f2..b290eca 100644 --- a/app/Item.php +++ b/app/Item.php @@ -24,4 +24,8 @@ class Item extends Model * @var array */ protected $hidden = []; + + public static function byEvent($event){ + return DB::table('users')->join('events', 'users.eid', '=', 'events.eid')->get(); + } } diff --git a/routes/web.php b/routes/web.php index fc34b84..3bfacf6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,28 +12,35 @@ */ $router->get('/', function () use ($router) { - return $router->app->version(); + return json_encode(array( + "framework_version" =>$router->app->version(), + "api_min_version"=>"1.0", + "api_max_version"=>"1.0", + )); }); -$router->group(['prefix' => '1'], function () use ($router) { - // events +//API version 1 +// copy this block and bump up version when implementing breaking changes +$router->group(['prefix' => '1'], function () use ($router) { + + // events $router->get('events', ['uses' => 'EventController@showAllEvents']); $router->get('event/{id}', ['uses' => 'EventController@showOneEvent']); $router->post('event', ['uses' => 'EventController@create']); $router->delete('event/{id}', ['uses' => 'EventController@delete']); $router->put('event/{id}', ['uses' => 'EventController@update']); -// containers + // containers $router->get('boxes', ['uses' => 'ContainerController@showAllContainers']); $router->get('box/{id}', ['uses' => 'ContainerController@showOneContainer']); $router->post('box', ['uses' => 'ContainerController@create']); $router->delete('box/{id}', ['uses' => 'ContainerController@delete']); $router->put('box/{id}', ['uses' => 'ContainerController@update']); -// items - $router->get('{event}/items', ['uses' => 'ItemController@showAllItems']); - $router->get('{event}/items/{query}', ['uses' => 'ItemController@searchAllItems']); + // items + $router->get('{event}/items', ['uses' => 'ItemController@showByEvent']); + $router->get('{event}/items/{query}', ['uses' => 'ItemController@searchByEvent']); $router->get('{event}/item/{id}', ['uses' => 'ItemController@showOneItem']); $router->post('{event}/item', ['uses' => 'ItemController@create']); $router->delete('{event}/item/{id}', ['uses' => 'ItemController@delete']);