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());
|
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);
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$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']);
|
||||||
|
@ -32,8 +39,8 @@ $router->group(['prefix' => '1'], function () use ($router) {
|
||||||
$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']);
|
||||||
|
|
Loading…
Reference in a new issue