diff --git a/api-rest/gateways/matchGateway.php b/api-rest/gateways/matchGateway.php new file mode 100644 index 0000000..69c1f19 --- /dev/null +++ b/api-rest/gateways/matchGateway.php @@ -0,0 +1,59 @@ +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; + } + +} + +?> \ No newline at end of file diff --git a/api-rest/gateways/userGateway.php b/api-rest/gateways/userGateway.php index f6190cb..bd28fe6 100644 --- a/api-rest/gateways/userGateway.php +++ b/api-rest/gateways/userGateway.php @@ -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 diff --git a/api-rest/index.php b/api-rest/index.php index 20f372b..b59a59f 100644 --- a/api-rest/index.php +++ b/api-rest/index.php @@ -1,7 +1,8 @@ deleteUser($usr); - $res=$usergw->getUsers(); + $res=$matchgw->getMatch("M0001"); + 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 @@ } } - + */ ?> \ No newline at end of file diff --git a/api-rest/model/match.php b/api-rest/model/match.php new file mode 100644 index 0000000..b8921f7 --- /dev/null +++ b/api-rest/model/match.php @@ -0,0 +1,22 @@ +id=$_id; + $this->inGame=$_inGame; + $this->idGame=$_idGame; + // Only one user at the moment of the creation + $this->listIdUsers=$_listIdUsers; + } +} + +?> \ No newline at end of file diff --git a/api-rest/model/user.php b/api-rest/model/user.php index d939086..92f83be 100644 --- a/api-rest/model/user.php +++ b/api-rest/model/user.php @@ -23,7 +23,6 @@ class User { $this->currentBobCoins=$_currentBobCoins; $this->totalBobCoins=$_totalBobCoins; $this->nbGamesPlayed=$_nbGamesPlayed; - } }