use version number in api endpoints

This commit is contained in:
j3d1 2019-11-30 13:47:54 +01:00
parent ccb3818da4
commit 36c6876d93
2 changed files with 33 additions and 27 deletions

View file

@ -8,18 +8,23 @@ use Illuminate\Http\Request;
class ItemController extends Controller class ItemController extends Controller
{ {
public function showAllEvents() public function showAllItems()
{ {
return response()->json(Item::all()); return response()->json(Item::all());
} }
public function showOneEvent($id) public function searchAllItems()
{
return response()->json(Item::all()); //TODO actually search
}
public function showOneItem($id)
{ {
return response()->json(Item::find($id)); return response()->json(Item::find($id));
} }
public function create(Request $request) public function create(Request $request)
{ {
$item = Item::create($request->all()); $item = Item::create($request->all());
return response()->json($item, 201); return response()->json($item, 201);
} }
@ -37,4 +42,4 @@ class ItemController extends Controller
Item::findOrFail($id)->delete(); Item::findOrFail($id)->delete();
return response('Deleted Successfully', 200); return response('Deleted Successfully', 200);
} }
} }

View file

@ -16,28 +16,29 @@ $router->get('/', function () use ($router) {
}); });
$router->group(['prefix' => 'api'], function () use ($router) { $router->group(['prefix' => 'api'], function () use ($router) {
// events
$router->get('events', ['uses' => 'EventController@showAllEvents']);
$router->get('events/{id}', ['uses' => 'EventController@showOneEvent']);
$router->post('events', ['uses' => 'EventController@create']);
$router->delete('events/{id}', ['uses' => 'EventController@delete']);
$router->put('events/{id}', ['uses' => 'EventController@update']);
});
$router->group(['prefix' => 'api'], function () use ($router) { $router->group(['prefix' => '1'], function () use ($router) {
// containers // events
$router->get('containers', ['uses' => 'ContainerController@showAllContainers']); $router->get('events', ['uses' => 'EventController@showAllEvents']);
$router->get('containers/{id}', ['uses' => 'ContainerController@showOneContainer']); $router->get('event/{id}', ['uses' => 'EventController@showOneEvent']);
$router->post('containers', ['uses' => 'ContainerController@create']); $router->post('event', ['uses' => 'EventController@create']);
$router->delete('containers/{id}', ['uses' => 'ContainerController@delete']); $router->delete('event/{id}', ['uses' => 'EventController@delete']);
$router->put('containers/{id}', ['uses' => 'ContainerController@update']); $router->put('event/{id}', ['uses' => 'EventController@update']);
});
$router->group(['prefix' => 'api'], function () use ($router) { // containers
// items $router->get('boxes', ['uses' => 'ContainerController@showAllContainers']);
$router->get('items', ['uses' => 'ItemController@showAllItems']); $router->get('box/{id}', ['uses' => 'ContainerController@showOneContainer']);
$router->get('items/{id}', ['uses' => 'ItemController@showOneItem']); $router->post('box', ['uses' => 'ContainerController@create']);
$router->post('items', ['uses' => 'ItemController@create']); $router->delete('box/{id}', ['uses' => 'ContainerController@delete']);
$router->delete('items/{id}', ['uses' => 'ItemController@delete']); $router->put('box/{id}', ['uses' => 'ContainerController@update']);
$router->put('items/{id}', ['uses' => 'ItemController@update']);
}); // items
$router->get('items', ['uses' => 'ItemController@showAllItems']);
$router->get('items/{query}', ['uses' => 'ItemController@searchAllItems']);
$router->get('item/{id}', ['uses' => 'ItemController@showOneItem']);
$router->post('item', ['uses' => 'ItemController@create']);
$router->delete('item/{id}', ['uses' => 'ItemController@delete']);
$router->put('item/{id}', ['uses' => 'ItemController@update']);
});
});