Commit 5969258d authored by Antoine Le Gonidec's avatar Antoine Le Gonidec

Move routes management in resource-specific controllers

parent b22e3813
<?php
namespace App\Http\Controllers;
use App\Archive;
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller;
class ArchivesController extends Controller {
/**
* Return count of supported archives
*
* @return int
*/
public function count() {
return Archive::all()->count();
}
/**
* Return list of supported archives
*
* @return Response
*/
public function list(Request $request) {
$list = Archive::getList(
$request->get('sort_by'),
$request->get('order')
);
return response()->json($list);
}
/**
* Return details of archive identified by given numeric id
*
* @param int $id
*
* @return Response
*/
public function show(Request $request, int $id) {
try {
$archive = Archive::findOrFail($id);
} catch (Exception $exception) {
$error = 'No archive found for id '.$id;
return response()->json([ 'error' => $error ], 404);
}
return response()->json($archive->toArray());
}
}
<?php
namespace App\Http\Controllers;
use App\Game;
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller;
class GamesController extends Controller {
/**
* Return count of supported games
*
* @return int
*/
public function count() {
return Game::all()->count();
}
/**
* Return list of supported games
*
* @return Response
*/
public function list(Request $request) {
$list = Game::getList(
$request->get('sort_by'),
$request->get('order')
);
return response()->json($list);
}
/**
* Return list of supported games matching a given pattern
*
* @return Response
*/
public function search(Request $request) {
$list = Game::getFilteredList(
$request->get('search'),
$request->get('sort_by'),
$request->get('order')
);
return response()->json($list);
}
/**
* Return details of games in given collection
*
* @param string $game_id
*
* @return Response
*/
public function collection(Request $request, string $game_id) {
$collection = Game::getCollection($game_id);
return response()->json($collection);
}
/**
* Return details of game identified by given numeric id
*
* @param int $id
*
* @return Response
*/
public function show(Request $request, int $id) {
try {
$game = Game::findOrFail($id);
} catch (Exception $exception) {
$error = 'No game found for id '.$id;
return response()->json([ 'error' => $error ], 404);
}
return response()->json($game->toArray());
}
}
<?php
namespace App\Http\Controllers;
use App\Script;
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller;
class ScriptsController extends Controller {
/**
* Return count of available scripts
*
* @return int
*/
public function count() {
return Script::all()->count();
}
/**
* Return list of available scripts
*
* @return Response
*/
public function list(Request $request) {
$list = Script::getList(
$request->get('sort_by'),
$request->get('order')
);
return response()->json($list);
}
/**
* Return details of script identified by given numeric id
*
* @param int $id
*
* @return Response
*/
public function show(Request $request, int $id) {
try {
$script = Script::findOrFail($id);
} catch (Exception $exception) {
$error = 'No script found for id '.$id;
return response()->json([ 'error' => $error ], 404);
}
return response()->json($script->toArray());
}
}
<?php <?php
use Illuminate\Http\Request;
use App\Archive;
use App\Game;
use App\Script;
$router->get('/', function () { return redirect('/games/list'); }); $router->get('/', function () { return redirect('/games/list'); });
// routes managed in app/Http/Controllers/GamesController.php
$router->group([ 'prefix' => 'games' ], function () use ($router) { $router->group([ 'prefix' => 'games' ], function () use ($router) {
$router->get('/count', function () { $router->get('/count', 'GamesController@count');
return Game::all()->count(); $router->get('/list', 'GamesController@list');
}); $router->get('/search', 'GamesController@search');
$router->get('/list', function (Request $request) { $router->get('/collection/{game_id}', 'GamesController@collection');
return response()->json( $router->get('/show/{id}', 'GamesController@show');
Game::getList(
$request->get('sort_by'),
$request->get('order')
)
);
});
$router->get('/collection/{game_id}', function (Request $request, string $game_id) {
return response()->json(
Game::getCollection($game_id)
);
});
$router->get('/show/{id}', function ($id) {
try {
$game = Game::findOrFail($id);
} catch (Exception $exception) {
$error = 'No game found for id '.$id;
return response()->json([ 'error' => $error ], 404);
}
return response()->json($game->toArray());
});
$router->get('/search', function (Request $request) {
return response()->json(
Game::getFilteredList(
$request->get('search'),
$request->get('sort_by'),
$request->get('order')
)
);
});
}); });
// routes managed in app/Http/Controllers/ScriptsController.php
$router->group([ 'prefix' => 'scripts' ], function () use ($router) { $router->group([ 'prefix' => 'scripts' ], function () use ($router) {
$router->get('/count', function () { $router->get('/count', 'ScriptsController@count');
return Script::all()->count(); $router->get('/list', 'ScriptsController@list');
}); $router->get('/show/{id}', 'ScriptsController@show');
$router->get('/list', function (Request $request) {
return response()->json(
Script::getList(
$request->get('sort_by'),
$request->get('order')
)
);
});
$router->get('/show/{id}', function ($id) {
try {
$script = Script::findOrFail($id);
} catch (Exception $exception) {
$error = 'No script found for id '.$id;
return response()->json([ 'error' => $error ], 404);
}
return response()->json($script->toArray());
});
}); });
// routes managed in app/Http/Controllers/ArchivesController.php
$router->group([ 'prefix' => 'archives' ], function () use ($router) { $router->group([ 'prefix' => 'archives' ], function () use ($router) {
$router->get('/count', function () { $router->get('/count', 'ArchivesController@count');
return Archive::all()->count(); $router->get('/list', 'ArchivesController@list');
}); $router->get('/show/{id}', 'ArchivesController@show');
$router->get('/list', function (Request $request) {
return response()->json(
Archive::getList(
$request->get('sort_by'),
$request->get('order')
)
);
});
$router->get('/show/{id}', function ($id) {
try {
$archive = Archive::findOrFail($id);
} catch (Exception $exception) {
$error = 'No archive found for id '.$id;
return response()->json([ 'error' => $error ], 404);
}
return response()->json($archive->toArray());
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment