Commit 7c262950 authored by Zohten's avatar Zohten

added public game endpoint

parent c1bd8146
<?php
// TODO : ID partie, Nom de la partie, nombres de joueurs déjà connectés
class GameController extends Controller
{
......@@ -21,6 +22,9 @@ class GameController extends Controller
case 'GET':
// If there is a uriParams, it is the /game/{id} endpoint
if ($uriParams) {
if ($uriParams[0]=='public'){
return $this->getAllPublicGames($uriParams[0]);
}
return $this->getGame($uriParams[0]);
}
// Else, it is the /game endpoint
......@@ -59,6 +63,18 @@ class GameController extends Controller
return $response;
}
/**
* (GET) Get all games in Game table
*
* @return Response
*/
protected function getAllPublicGames()
{
$games = Game::getListPublic();
$response = Response::okResponse(json_encode($games, JSON_PRETTY_PRINT));
return $response;
}
/**
* (POST) Add a new game in Game table
*
......
......@@ -15,6 +15,12 @@ class Game extends Model
return $stm->fetchAll();
}
public static function getListPublic()
{
$stm = parent::exec('GAME_LIST_PUBLIC');
return $stm->fetchAll();
}
public static function getRow($id)
{
$stm = parent::exec('GAME_GET_WITH_ID', ['id' => $id]);
......
......@@ -5,6 +5,13 @@ Game::addSqlQuery(
'SELECT * FROM MJ_GAME'
);
Game::addSqlQuery(
'GAME_LIST_PUBLIC',
'SELECT g.ID_GAME
FROM MJ_GAME as g
WHERE g.PRIVATE=0'
);
Game::addSqlQuery(
'GAME_GET_WITH_ID',
'SELECT * FROM MJ_GAME WHERE ID_GAME=:id'
......
......@@ -4,6 +4,9 @@ GET http://localhost/index.php/game
### Récupérer la game avec id 3
GET http://localhost/index.php/game/3
### Récupérer toutes les games publiques
GET http://localhost/index.php/game/public
### Ouverture d'une game
POST http://localhost/index.php/game
......
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