Skip to content
Snippets Groups Projects
Commit 6fdf01af authored by SASSU Thomas's avatar SASSU Thomas
Browse files

Partie 6

parent 4229a9e7
No related branches found
No related tags found
No related merge requests found
......@@ -26,12 +26,12 @@ $app->get('/',function () use ($app) {
$app->get('/api/games/:id',function ($id) {
$c = new ControleurGame();
$c->getGame($id);
});
})->name('getGame');
// Affiche tous les jeu paginé au format JSON
$app->get('/api/games/',function () {
$c = new ControleurGame();
$c->getGames();
})->name('getGame');
})->name('getGames');
// Affiche les commentaires d'un jeu
$app->get('/api/games/:id/comments',function ($id) {
$c = new ControleurGame();
......
......@@ -9,8 +9,14 @@ use Slim\Slim;
class ControleurGame
{
public function getGame($id){
$route = Slim::getInstance()->request->getResourceUri();
$game = Game::where('id', '=', $id)->first();
$v = new VueGame(json_encode($game));
$results['game'] = $game;
$results['links'] = [
"comments" =>["href" => $route."/comments"] ,
"characters" =>["href" => $route."/characters"]
];
$v = new VueGame(json_encode($results));
$v->render('getGame');
}
......@@ -20,7 +26,7 @@ class ControleurGame
$response = Game::paginate(200, ['*'], 'page', $page);
$json = (json_decode(json_encode($response),true));
foreach ($json['data'] as $game) {
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getGame'));
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getGames'));
$url = $route[1]."{$game['id']}";
$results['games'][] = ["game" => $game, "links" => ["self" => ["href" => $url]]];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment