ADD : functions for the Match, end of the users databased sized
continuous-integration/drone/push Build is failing Details

stub-api
Lucie Bedouret 2 years ago
parent 7291994ad0
commit e47e97e6e7

@ -0,0 +1,59 @@
<?php
include('model/match.php');
class MatchGateway{
// Object Attributes
private $connection;
// Constructor
public function __construct($con){
$this->connection=$con;
}
// Fucntions executing SQL requests on database
/*
* get : trouver un match grâce à un id de joueur
* put : pour modifier le match
* post : créer un match dans la bd
* delete : supprimer un match dans la bd
*/
// Function executing get method to find a match
public function getMatch(string $matchId){
$query1="SELECT id, inGame, idGame FROM Matchs WHERE id = :id";
$query2="SELECT idUser FROM InMatch WHERE idMatch=:id";
$arg=array('id' => array($matchId, PDO::PARAM_STR));
$this->connection->execQuery($query2, $arg);
$res=$this->connection->getRes();
foreach($res as $row){
$tabUser[] = $row['idUser'];
}
$this->connection->execQuery($query1, $arg);
$res=$this->connection->getRes();
foreach($res as $row){
$match = new Matchs($row['id'],$row['inGame'],$row['idGame'],$tabUser);
}
return $match;
}
// Function executing post method to create a match in database
public function postMatch(Matchs $m){
$query1="INSERT INTO Matchs VALUES(:idMatch,0,:idGame)";
$query2="INSERT INTO InMatch VALUES(:idMatch,:idUser)";
$arg1=array('idMatch'=>array($m->id, PDO::PARAM_STR),
'idGame'=>array($m->idGame, PDO::PARAM_STR));
$this->connection->execQuery($query1,$arg1);
foreach($m->listIdUsers as $idUsr){
$arg2=array('idMatch'=>array($m->id, PDO::PARAM_STR),
'idUser'=>array($idUsr, PDO::PARAM_STR));
$this->connection->execQuery($query2,$arg2);
}
return;
}
}
?>

@ -32,7 +32,6 @@ class UserGateway{
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed']);
}
return $usr;
}
// execute get method to find one user by his username in database

@ -1,7 +1,8 @@
<?php
include ("./dbConnection.php");
include ("./gateways/userGateway.php");
include ('dbConnection.php');
include ('gateways/userGateway.php');
include ('gateways/matchGateway.php');
// Connection to database
// A changer quand la base de données sera hébergée, comment masquer les var?
@ -9,19 +10,25 @@
$username="root";
$password="root";
// Initializing Database
$database = new DatabaseConnection($dsn,$username,$password);
// Initializing Gateways
$usergw = new UserGateway($database);
$matchgw = new MatchGateway($database);
// Testing get method on matches
$res=$matchgw->getMatch("M0001");
// test postUser
$usr = new User("U0004","billy","bulbe","francais","F","2023-03-12",10,10,2);
$usergw->deleteUser($usr);
$res=$usergw->getUsers();
echo json_encode($res);
// Managing request and routing
// Managing request, routing and sending responses
/*
$requestMethod = $_SERVER['REQUEST_METHOD'];
$requestName = $_REQUEST['fname'];
if(empty($requestName)){
header("HTTP/1.0 400 Request Name Empty");
http_response_code(400);
@ -62,9 +69,7 @@
case 'POST':
switch ($requestName){
case 'postUser':
// rcreate a new user
$res= $usergw->postUser();
echo json_encode($res);
// create a new user and add it in database
break;
case 'postMatch':
@ -86,9 +91,9 @@
case 'putMatch':
break;
/* case 'putMessage':
case 'putMessage':
break; */
break;
case 'putConversation ':
break;
@ -103,9 +108,9 @@
case 'delMatch':
break;
/* case 'delMessage':
case 'delMessage':
break; */
break;
case 'delConversation ':
break;
@ -119,6 +124,6 @@
}
}
*/
?>

@ -0,0 +1,22 @@
<?php
// appelé "Matchs" car match sans s ne marche pas
class Matchs{
// Object attributes
public string $id;
public bool $inGame;
public string $idGame;
public $listIdUsers;
public function __construct(string $_id,bool $_inGame, string $_idGame, $_listIdUsers){
$this->id=$_id;
$this->inGame=$_inGame;
$this->idGame=$_idGame;
// Only one user at the moment of the creation
$this->listIdUsers=$_listIdUsers;
}
}
?>

@ -23,7 +23,6 @@ class User {
$this->currentBobCoins=$_currentBobCoins;
$this->totalBobCoins=$_totalBobCoins;
$this->nbGamesPlayed=$_nbGamesPlayed;
}
}

Loading…
Cancel
Save