filter items by event
This commit is contained in:
parent
77450dfff9
commit
8d611a625b
3 changed files with 30 additions and 14 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
|
|
Loading…
Reference in a new issue