From 6fdf01afe30d70ffb6ea99b7265fd807080f31dc Mon Sep 17 00:00:00 2001
From: SASSU Thomas <thomas.sassu5@etu.univ-lorraine.fr>
Date: Mon, 23 Mar 2020 20:30:53 +0100
Subject: [PATCH] Partie 6

---
 GamePedia/index.php                          |  4 ++--
 GamePedia/src/controleurs/ControleurGame.php | 10 ++++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/GamePedia/index.php b/GamePedia/index.php
index 63bd77c..62540f3 100644
--- a/GamePedia/index.php
+++ b/GamePedia/index.php
@@ -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();
diff --git a/GamePedia/src/controleurs/ControleurGame.php b/GamePedia/src/controleurs/ControleurGame.php
index e4080f1..e5e3598 100644
--- a/GamePedia/src/controleurs/ControleurGame.php
+++ b/GamePedia/src/controleurs/ControleurGame.php
@@ -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]]];
         }
-- 
GitLab