filter items by event

This commit is contained in:
j3d1 2019-12-01 18:30:25 +01:00
parent 77450dfff9
commit 8d611a625b
3 changed files with 30 additions and 14 deletions

View file

@ -13,31 +13,36 @@ class ItemController extends Controller
return response()->json(Item::all()); 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)); return response()->json(Item::find($id));
} }
public function create(Request $request) public function create($event, Request $request)
{ {
$item = Item::create($request->all()); $item = Item::create($request->all());
return response()->json($item, 201); return response()->json($item, 201);
} }
public function update($id, Request $request) public function update($event, $id, Request $request)
{ {
$item = Item::findOrFail($id); $item = Item::findOrFail($id);
$item->update($request->all()); $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(); Item::findOrFail($id)->delete();
return response('Deleted Successfully', 200); return response('Deleted Successfully', 200);

View file

@ -24,4 +24,8 @@ class Item extends Model
* @var array * @var array
*/ */
protected $hidden = []; protected $hidden = [];
public static function byEvent($event){
return DB::table('users')->join('events', 'users.eid', '=', 'events.eid')->get();
}
} }

View file

@ -12,28 +12,35 @@
*/ */
$router->get('/', function () use ($router) { $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('events', ['uses' => 'EventController@showAllEvents']);
$router->get('event/{id}', ['uses' => 'EventController@showOneEvent']); $router->get('event/{id}', ['uses' => 'EventController@showOneEvent']);
$router->post('event', ['uses' => 'EventController@create']); $router->post('event', ['uses' => 'EventController@create']);
$router->delete('event/{id}', ['uses' => 'EventController@delete']); $router->delete('event/{id}', ['uses' => 'EventController@delete']);
$router->put('event/{id}', ['uses' => 'EventController@update']); $router->put('event/{id}', ['uses' => 'EventController@update']);
// containers // containers
$router->get('boxes', ['uses' => 'ContainerController@showAllContainers']); $router->get('boxes', ['uses' => 'ContainerController@showAllContainers']);
$router->get('box/{id}', ['uses' => 'ContainerController@showOneContainer']); $router->get('box/{id}', ['uses' => 'ContainerController@showOneContainer']);
$router->post('box', ['uses' => 'ContainerController@create']); $router->post('box', ['uses' => 'ContainerController@create']);
$router->delete('box/{id}', ['uses' => 'ContainerController@delete']); $router->delete('box/{id}', ['uses' => 'ContainerController@delete']);
$router->put('box/{id}', ['uses' => 'ContainerController@update']); $router->put('box/{id}', ['uses' => 'ContainerController@update']);
// items // items
$router->get('{event}/items', ['uses' => 'ItemController@showAllItems']); $router->get('{event}/items', ['uses' => 'ItemController@showByEvent']);
$router->get('{event}/items/{query}', ['uses' => 'ItemController@searchAllItems']); $router->get('{event}/items/{query}', ['uses' => 'ItemController@searchByEvent']);
$router->get('{event}/item/{id}', ['uses' => 'ItemController@showOneItem']); $router->get('{event}/item/{id}', ['uses' => 'ItemController@showOneItem']);
$router->post('{event}/item', ['uses' => 'ItemController@create']); $router->post('{event}/item', ['uses' => 'ItemController@create']);
$router->delete('{event}/item/{id}', ['uses' => 'ItemController@delete']); $router->delete('{event}/item/{id}', ['uses' => 'ItemController@delete']);