Commit 7573ddfb authored by Zohten's avatar Zohten

we can now add games

parent 7f257120
...@@ -26,6 +26,10 @@ class GameController extends Controller ...@@ -26,6 +26,10 @@ class GameController extends Controller
// Else, it is the /game endpoint // Else, it is the /game endpoint
return $this->getAllGames(); return $this->getAllGames();
break; break;
case 'POST':
$body = $this->request->getData();
return $this->newGame($body);
break;
} }
$message = json_encode(["message" => "unsupported parameters or method in game"]); $message = json_encode(["message" => "unsupported parameters or method in game"]);
return Response::errorResponse($message); return Response::errorResponse($message);
...@@ -54,4 +58,18 @@ class GameController extends Controller ...@@ -54,4 +58,18 @@ class GameController extends Controller
$response = Response::okResponse(json_encode($games, JSON_PRETTY_PRINT)); $response = Response::okResponse(json_encode($games, JSON_PRETTY_PRINT));
return $response; return $response;
} }
/**
* (POST) Add a new round in Round table
*
* @param array $array array containing ID_GAME, PREVAILING_WIND ,SEED
* @return Response
*/
protected function newGame($array)
{
Game::createGame($array);
$message = json_encode(["message" => 'Game succesfully created!']);
$response = Response::createdResponse($message);
return $response;
}
} }
\ No newline at end of file
...@@ -21,4 +21,11 @@ class Game extends Model ...@@ -21,4 +21,11 @@ class Game extends Model
return $stm->fetchAll(); return $stm->fetchAll();
} }
public static function createGame($array)
{
$begin_date = date('Y-m-d H:i:s');
$pimped_array = array_merge($array, ['creation_time'=>$begin_date]);
$stm = parent::exec('GAME_CREATE', $pimped_array);
}
} }
\ No newline at end of file
...@@ -8,4 +8,10 @@ Game::addSqlQuery( ...@@ -8,4 +8,10 @@ Game::addSqlQuery(
Game::addSqlQuery( Game::addSqlQuery(
'GAME_GET_WITH_ID', 'GAME_GET_WITH_ID',
'SELECT * FROM MJ_GAME WHERE ID_GAME=:id' 'SELECT * FROM MJ_GAME WHERE ID_GAME=:id'
);
Game::addSqlQuery(
'GAME_CREATE',
'INSERT INTO MJ_GAME (ID_GAME, PRIVATE, CREATION_TIME)
VALUES (NULL, :is_private, :creation_time)'
); );
\ No newline at end of file
...@@ -2,4 +2,11 @@ ...@@ -2,4 +2,11 @@
GET http://localhost/index.php/game GET http://localhost/index.php/game
### Récupérer la game avec id 3 ### Récupérer la game avec id 3
GET http://localhost/index.php/game/3 GET http://localhost/index.php/game/3
\ No newline at end of file
### Ouverture d'une game
POST http://localhost/index.php/game
{
"is_private": "1"
}
\ No newline at end of file
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