From 2ded8129b12ec980d773df9abfd7fff6ab5ca33c Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 4 Sep 2016 11:54:48 +0100 Subject: [PATCH] Test game --- src/Api/ScoreControllerProvider.php | 14 ++++++++++++-- www/index.php | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Api/ScoreControllerProvider.php b/src/Api/ScoreControllerProvider.php index 2c0457a..28db12a 100644 --- a/src/Api/ScoreControllerProvider.php +++ b/src/Api/ScoreControllerProvider.php @@ -43,10 +43,20 @@ class ScoreControllerProvider implements ControllerProviderInterface return $app['serializer']->serialize($user, 'json'); }); + $controllers->get('/games/{gameId}', function(Request $request, Application $app) { + + $game = $request->attributes->get('game'); + + return $app['serializer']->serialize($game, 'json'); + + }) + ->bind('game') + ->convert('game', function($game, Request $request) use ($app){ return $app['entity.manager']->getRepository(Models\Game::class)->find($request->attributes->get('gameId'));}); + /** * Expects a full game + hits in the request */ - $controllers->post('/me/games', function (Request $request, Application $app) { + $controllers->post('/games', function (Request $request, Application $app) { $data = json_decode($request->getContent(), true); $token = $app['security.token_storage']->getToken(); $user = $token->getUser(); @@ -99,7 +109,7 @@ class ScoreControllerProvider implements ControllerProviderInterface $hit->setPoint($i, $data_hit['points']["$i"]['x'], $data_hit['points']["$i"]['y']); } - + // set game appends hit to game $hit->setGame($game); diff --git a/www/index.php b/www/index.php index 1309ead..c4274c2 100644 --- a/www/index.php +++ b/www/index.php @@ -19,6 +19,11 @@ $app = new Silex\Application([ define('USER_ID_FIELD', 'id'); +$app['entity.manager'] = function() { + return EmotionHero\Application::getInstance()->getEm(); +}; + + $app['security.jwt'] = [ 'secret_key' => $eh->getConfig()['secret_key'],