|
|
@ -27,19 +27,11 @@
|
|
|
|
$gamegw = new GameGateway($database);
|
|
|
|
$gamegw = new GameGateway($database);
|
|
|
|
$skingw = new SkinGateway($database);
|
|
|
|
$skingw = new SkinGateway($database);
|
|
|
|
|
|
|
|
|
|
|
|
// Testing
|
|
|
|
// Managing request, routing and sending
|
|
|
|
$res=$gamegw->getGames();
|
|
|
|
// ------
|
|
|
|
echo json_encode($res);
|
|
|
|
// RAPPEL POUR MOI MÊME : NE PAS OUBLIER DE FAIRE DES TRY CATCH !!!!!!!
|
|
|
|
$res=$gamegw->getGameById("G0002");
|
|
|
|
// ------
|
|
|
|
echo json_encode($res);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$res=$skingw->getSkins();
|
|
|
|
|
|
|
|
echo json_encode($res);
|
|
|
|
|
|
|
|
$res=$skingw->getSkinById("S0001");
|
|
|
|
|
|
|
|
echo json_encode($res);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Managing request, routing and sending responses
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
|
|
|
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
|
|
|
$requestName = $_REQUEST['fname'];
|
|
|
|
$requestName = $_REQUEST['fname'];
|
|
|
|
|
|
|
|
|
|
|
@ -53,27 +45,86 @@
|
|
|
|
switch ($requestName){
|
|
|
|
switch ($requestName){
|
|
|
|
case 'getUser':
|
|
|
|
case 'getUser':
|
|
|
|
if (!empty($_GET["id"])){
|
|
|
|
if (!empty($_GET["id"])){
|
|
|
|
//read an user by his id
|
|
|
|
//read an user by its id
|
|
|
|
$id = intval($_GET["id"]);
|
|
|
|
$id = intval($_GET["id"]);
|
|
|
|
$res=$usergw->getUserById($id);
|
|
|
|
try{
|
|
|
|
|
|
|
|
$res=$usergw->getUserById($id);
|
|
|
|
|
|
|
|
//retourner le résultat
|
|
|
|
|
|
|
|
} catch (PDOException $e){
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (!empty($_GET["username"])){
|
|
|
|
elseif (!empty($_GET["username"])){
|
|
|
|
// read an user by his username
|
|
|
|
// read an user by his username
|
|
|
|
$username = intval($_GET["username"]);
|
|
|
|
$username = intval($_GET["username"]);
|
|
|
|
$res=$usergw->getUserByUsername($username);
|
|
|
|
try{
|
|
|
|
|
|
|
|
$res=$usergw->getUserByUsername($username);
|
|
|
|
|
|
|
|
//retourner le résultat
|
|
|
|
|
|
|
|
} catch (PDOException $e){
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
|
|
|
|
header("HTTP/1.0 405 Missing argument id or username");
|
|
|
|
|
|
|
|
http_response_code(405);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'getMatch':
|
|
|
|
case 'getMatch':
|
|
|
|
|
|
|
|
if(!empty($_GET["id"])){
|
|
|
|
|
|
|
|
//read a match by its id
|
|
|
|
|
|
|
|
$id = intval($_GET["id"]);
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
$res=$matchgw->getMatchById($id);
|
|
|
|
|
|
|
|
//retourner le résultat
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
header("HTTP/1.0 405 Missing argument id");
|
|
|
|
|
|
|
|
http_response_code(405);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'getMessage':
|
|
|
|
case 'getConversation':
|
|
|
|
|
|
|
|
if(!emptyempty($_GET["id"])){
|
|
|
|
|
|
|
|
// read conversations by the id of a user
|
|
|
|
|
|
|
|
$idUsr = intval($_GET["id"]);
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
$res=$conversationgw->getConversations($idUsr);
|
|
|
|
|
|
|
|
// retourner le résultat
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
header("HTTP/1.0 405 Missing argument idUsr");
|
|
|
|
|
|
|
|
http_response_code(405);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'getConversation ':
|
|
|
|
case 'getSkin':
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
$res = $skingw->getSkins();
|
|
|
|
|
|
|
|
//retourner le résultat
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'getGames':
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
$res = $gamegw->getGames();
|
|
|
|
|
|
|
|
//retourner le résultat
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
header("HTTP/1.0 406 unknown method");
|
|
|
|
|
|
|
|
http_response_code(406); // Le bon code ?
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -81,7 +132,16 @@
|
|
|
|
case 'POST':
|
|
|
|
case 'POST':
|
|
|
|
switch ($requestName){
|
|
|
|
switch ($requestName){
|
|
|
|
case 'postUser':
|
|
|
|
case 'postUser':
|
|
|
|
// create a new user and add it in database
|
|
|
|
if(!empty($_POST["id"])){
|
|
|
|
|
|
|
|
$usr = new User($_POST["id"],$_POST["username"],$_POST["password"],$_POST["nationality"],$_POST["sex"],$_POST["dateOfBirth"],0,0,0,"S0001",[]);
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
$usergw->postUser($usr);
|
|
|
|
|
|
|
|
http_response_code(200);
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
header("HTTP/1.0 ".$e->getMessage());
|
|
|
|
|
|
|
|
http_response_code(600); // Quel code pour les erreurs PDO?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'postMatch':
|
|
|
|
case 'postMatch':
|
|
|
|
|
|
|
|
|
|
|
@ -136,6 +196,5 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
?>
|