ADD : skin and games methods
continuous-integration/drone/push Build is failing Details

stub-api
Lucie Bedouret 2 years ago
parent fb0d6ec69a
commit 5c0ad12fd9

@ -33,8 +33,8 @@ class ConversationGateway{
$tabIdMessages=NULL;
$tabMessages=NULL;
$query1 = "SELECT idConversation FROM InConversation WHERE idUser=:idUser";
$query2 = "SELECT idUser FROM InConversation WHERE idConversation=:idConv";
$query1 = "SELECT idConversation FROM Use WHERE idUser=:idUser";
$query2 = "SELECT idUser FROM Use WHERE idConversation=:idConv";
$query3 = "SELECT idMessage FROM Have WHERE idConversation=:idConv";
$query4 = "SELECT id, message, idSender FROM Message WHERE id=:id";
$query5 = "SELECT id, nom FROM Conversation WHERE id=:idConv";
@ -88,7 +88,7 @@ class ConversationGateway{
/// Parameters : * $c (Conversation): conversation we want to insert in database
public function postConversation(Conversation $c): void{
$query1 = "INSERT INTO Conversation VALUES(:idConv,:name)";
$query2 = "INSERT INTO InConversation VALUES(:idUser,:idConv)";
$query2 = "INSERT INTO Use VALUES(:idUser,:idConv)";
$arg1 = array('idConv'=>array($c->id,PDO::PARAM_STR),
'name'=>array($c->name, PDO::PARAM_STR));
@ -108,11 +108,11 @@ class ConversationGateway{
$query7 = "SELECT idMessage FROM Have WHERE idConversation=:idConv";
$query8 = "DELETE FROM Message WHERE id = :id";
$query1 = "DELETE FROM Have WHERE idConversation = :idConv";
$query2 = "DELETE FROM InConversation WHERE idConversation = :idConv";
$query2 = "DELETE FROM Use WHERE idConversation = :idConv";
$query3 = "UPDATE Conversation SET nom=:nom WHERE id=:id";
$query4 = "INSERT INTO Have VALUES (:idConv,:idMessage)";
$query5 = "INSERT INTO Message VALUES(:id,:message,:idSender)";
$query6 = "INSERT INTO InConversation VALUES(:idUsr,:idConv)";
$query6 = "INSERT INTO Use VALUES(:idUsr,:idConv)";
$arg1 = array('idConv'=>array($c->id,PDO::PARAM_STR));
@ -152,7 +152,7 @@ class ConversationGateway{
public function deleteConversation(Conversation $c):void{
$query1 = "DELETE FROM Message WHERE id=:id";
$query2 = "DELETE FROM Have WHERE idConversation = :idConv";
$query3 = "DELETE FROM InConversation WHERE idConversation = :idConv";
$query3 = "DELETE FROM Use WHERE idConversation = :idConv";
$query4 = "DELETE FROM Conversation WHERE id = :idConv";
foreach($c->listMessages as $msg){

@ -0,0 +1,46 @@
<?php
require_once('model/game.php');
class GameGateway{
private $connecion;
// Constructor
public function __construct($_connection){
$this->connection=$_connection;
}
/* Functions implemented to manage games' data from database
* getGames : returning all the games found in database
* getGameById : returning a game found in database with its id
*/
/// Brief : Returning all the games found in database
public function getGames():?array{
$tabGames=null;
$query="SELECT * FROM Game";
$this->connection->execQuery($query,[]);
$res = $this->connection->getRes();
foreach($res as $row){
$tabGames[]= new Game($row['id'],$row['name'],$row['image']);
}
return $tabGames;
}
/// Brief : Returning a game found in database with its id
/// Parameters : * $id (string): identifier of the game we are looking for
public function getGameById(string $id):?Game{
$game=null;
$query="SELECT * FROM Game WHERE id=:id";
$arg=array('id'=>array($id,PDO::PARAM_STR));
$this->connection->execQuery($query,$arg);
$res=$this->connection->getRes();
foreach($res as $row){
$game= new Game($row['id'],$row['name'],$row['image']);
}
return $game;
}
}
?>

@ -25,7 +25,7 @@ class MatchGateway{
public function getMatch(string $matchId):?Matchs{
$match=NULL;
$query1="SELECT id, inGame, idGame FROM Matchs WHERE id = :id";
$query2="SELECT idUser FROM InMatch WHERE idMatch=:id";
$query2="SELECT idUser FROM Play WHERE idMatch=:id";
$arg=array('id' => array($matchId, PDO::PARAM_STR));
$this->connection->execQuery($query2, $arg);
$res=$this->connection->getRes();
@ -45,7 +45,7 @@ class MatchGateway{
/// Parameters : * $u (Matchs): match we want to insert in database
public function postMatch(Matchs $m){
$query1="INSERT INTO Matchs VALUES(:idMatch,0,:idGame)";
$query2="INSERT INTO InMatch VALUES(:idMatch,:idUser)";
$query2="INSERT INTO Play VALUES(:idMatch,:idUser)";
$arg1=array('idMatch'=>array($m->id, PDO::PARAM_STR),
'idGame'=>array($m->idGame, PDO::PARAM_STR));
$this->connection->execQuery($query1,$arg1);
@ -62,8 +62,8 @@ class MatchGateway{
public function putMatch(Matchs $m){
$query1="UPDATE Matchs SET inGame= :inGame WHERE id=:id";
//Peut-etre la possibilité de faire mieux???
$query2="DELETE FROM InMatch WHERE idMatch=:idMatch";
$query3="INSERT INTO InMatch VALUES(:idMatch,:idUser)";
$query2="DELETE FROM Play WHERE idMatch=:idMatch";
$query3="INSERT INTO Play VALUES(:idMatch,:idUser)";
$arg1=array('inGame'=>array($m->inGame, PDO::PARAM_BOOL),
'id'=>array($m->id,PDO::PARAM_STR));
$arg2=array('idMatch'=>array($m->id,PDO::PARAM_STR));
@ -80,7 +80,7 @@ class MatchGateway{
/// Brief : Deleting a match from database
/// Parameters : * $u (Matchs): match we want to delete from database
public function deleteMatch(Matchs $m){
$query1="DELETE FROM InMatch WHERE idMatch=:id";
$query1="DELETE FROM Play WHERE idMatch=:id";
$query2="DELETE FROM Matchs WHERE id=:id";
$arg=array('id'=>array($m->id, PDO::PARAM_STR));
$this->connection->execQuery($query1,$arg);

@ -0,0 +1,45 @@
<?php
require_once('model/skin.php');
class SkinGateway{
private $connection;
public function __construct($_connection){
$this->connection=$_connection;
}
/* Functions implemented to manage skins' data from database
* getGames : returning all the skins found in database
* getGameById : returning a skin found in database with its id
*/
/// Brief : Returning all the skins found in database
public function getSkins():?array{
$tabSkins=null;
$query="SELECT * FROM Skin";
$this->connection->execQuery($query,[]);
$res = $this->connection->getRes();
foreach($res as $row){
$tabSkins[]= new Game($row['id'],$row['name'],$row['image']);
}
return $tabSkins;
}
/// Brief : Returning a skin found in database with its id
/// Parameters : * $id (string): identifier of the skin we are looking for
public function getSkinById(string $id):?Game{
$skin=null;
$query="SELECT * FROM Skin WHERE id=:id";
$arg=array('id'=>array($id,PDO::PARAM_STR));
$this->connection->execQuery($query,$arg);
$res=$this->connection->getRes();
foreach($res as $row){
$skin= new Game($row['id'],$row['name'],$row['image']);
}
return $skin;
}
}
?>

@ -13,8 +13,8 @@ class UserGateway{
/* Functions implemented to manage user's data from database
* getUsers : returning an array of users containing all the user stored in database
* getUserById : returning an user found in database with his id
* getUserByUsername : returning an user found in database with his username
* getUserById : returning an user found in database with its id
* getUserByUsername : returning an user found in database with its username
* getUserForConnection : returning an user if there is a correspondance between
the username and the password, used for connection
* getLastId : returning the last Id of the users
@ -29,7 +29,7 @@ class UserGateway{
public function getUserById(string $id):?User{
$usr=NULL;
$query= "SELECT * FROM User U WHERE id = :id ";
$query2="SELECT idSkin FROM HasSkin WHERE idUser=:id";
$query2="SELECT idSkin FROM Own WHERE idUser=:id";
$arg= array('id'=> array($id,PDO::PARAM_STR));
$this->connection->execQuery($query2,$arg);
$res=$this->connection->getRes();
@ -39,7 +39,7 @@ class UserGateway{
$this->connection->execQuery($query,$arg);
$res=$this->connection->getRes();
foreach($res as $row){
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed'],$row['currentIdSkin'],$tabSkin);
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed'],$row['currentSkin'],$tabSkin);
}
return $usr;
}
@ -50,12 +50,12 @@ class UserGateway{
$usr=NULL;
$query= "SELECT * FROM User U WHERE username = :username ";
$query2="SELECT idSkin FROM HasSkin WHERE idUser=:id";
$query2="SELECT idSkin FROM Own WHERE idUser=:id";
$arg = array('username'=>array($username,PDO::PARAM_STR));
$this->connection->execQuery($query,$arg);
$res=$this->connection->getRes();
foreach($res as $row){
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed'],$row['currentIdSkin'],null);
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed'],$row['currentSkin'],null);
}
$arg2=array('id'=>array($usr->id, PDO::PARAM_STR));
$this->connection->execQuery($query2,$arg2);
@ -75,12 +75,12 @@ class UserGateway{
public function getUserForConnection(string $username, string $password):?User{
$usr=NULL;
$query= "SELECT * FROM User U WHERE username = :username AND password = :password";
$query2="SELECT idSkin FROM HasSkin WHERE idUser=:id";
$query2="SELECT idSkin FROM Own WHERE idUser=:id";
$arg = array('username'=>array($username,PDO::PARAM_STR),'password'=>array($password,PDO::PARAM_STR));
$this->connection->execQuery($query,$arg);
$res=$this->connection->getRes();
foreach($res as $row){
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed'],$row['currentIdSkin'],null);
$usr = new User ($row['id'],$row['username'],$row['password'],$row['nationality'],$row['sex'],$row['dateOfBirth'],$row['currentBobCoins'],$row['totalBobCoins'],$row['nbGamesPlayed'],$row['currentSkin'],null);
}
$arg2=array('id'=>array($usr->id, PDO::PARAM_STR));
$this->connection->execQuery($query2,$arg2);
@ -111,7 +111,7 @@ class UserGateway{
return;
}
$query = "INSERT INTO User VALUES (:id, :username, :password, :nationality, :sex, :dateOfBirth, 0, 0, 0, 'S0001')";
$query2 = "INSERT INTO HasSkin VALUES(:id,'S0001')";
$query2 = "INSERT INTO Own VALUES(:id,'S0001')";
$arg=array('id' => array($u->id, PDO::PARAM_STR),
'username' => array($u->username, PDO::PARAM_STR),
'password' => array($u->password, PDO::PARAM_STR),
@ -126,9 +126,9 @@ class UserGateway{
/// Brief : Modifying an EXISTING user in database
/// Parameters : * $u (User): user we want to update in database
public function putUser(User $u){
$query="UPDATE User SET username = :username, password=:password, sex=:sex, nationality=:nationality, currentBobCoins=:currentBobCoins, totalBobCoins=:totalBobCoins, nbGamesPlayed=:nbGamesPlayed, currentIdSkin=:currentIdSkin WHERE id=:id";
$query2="DELETE FROM HasSkin WHERE idUser=:id";
$query3="INSERT INTO HasSkin VALUES(:idUsr,:idSkin)";
$query="UPDATE User SET username = :username, password=:password, sex=:sex, nationality=:nationality, currentBobCoins=:currentBobCoins, totalBobCoins=:totalBobCoins, nbGamesPlayed=:nbGamesPlayed, currentSkin=:currentSkin WHERE id=:id";
$query2="DELETE FROM Own WHERE idUser=:id";
$query3="INSERT INTO Own VALUES(:idUsr,:idSkin)";
$arg=array(':id' => array($u->id, PDO::PARAM_STR),
':username' => array($u->username, PDO::PARAM_STR),
':password' => array($u->password, PDO::PARAM_STR),
@ -137,7 +137,7 @@ class UserGateway{
':currentBobCoins' => array($u->currentBobCoins, PDO::PARAM_INT),
':totalBobCoins' => array($u->totalBobCoins, PDO::PARAM_INT),
':nbGamesPlayed' => array($u->nbGamesPlayed, PDO::PARAM_INT),
':currentIdSkin'=> array($u->currentIdSkin, PDO::PARAM_STR));
':currentSkin'=> array($u->currentSkin, PDO::PARAM_STR));
$arg2=array('id'=>array($u->id,PDO::PARAM_STR));
$this->connection->execQuery($query, $arg);
$this->connection->execQuery($query2,$arg2);

@ -8,6 +8,8 @@
include ('gateways/userGateway.php');
include ('gateways/matchGateway.php');
include ('gateways/conversationGataway.php');
include ('gateways/gameGateway.php');
include ('gateways/skinGateway.php');
// Connection to database
// A changer quand la base de données sera hébergée, comment masquer les var?
@ -22,20 +24,25 @@
$usergw = new UserGateway($database);
$matchgw = new MatchGateway($database);
$conversationgw = new ConversationGateway($database);
$gamegw = new GameGateway($database);
$skingw = new SkinGateway($database);
// Testing conversation/messages methods
$listUser=array("U0001","U0004","U0005");
$listMessages= array(new Message("ME005","coucou","U0001"), new Message("ME006","ca va","U0004"), new Message("ME007","bien et toi?","U0001"));
$newConv = new Conversation("C0006","yémen",$listMessages,$listUser);
$conversationgw->deleteConversation($newConv);
// Testing
$res=$gamegw->getGames();
echo json_encode($res);
$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'];
$requestName = $_REQUEST['fname'];
if(empty($requestName)){
header("HTTP/1.0 400 Request Name Empty");
http_response_code(400);

@ -0,0 +1,17 @@
<?php
class Game{
public string $id;
public string $name;
public string $image;
public function __construct(string $_id, string $_name, string $_image){
$this->id=$_id;
$this->name=$_name;
$this->image=$_image;
}
}
?>

@ -0,0 +1,16 @@
<?php
class Skin{
public string $id;
public string $name;
public string $image;
public function __construct(string $_id, string $_name, string $_image){
$this->id=$_id;
$this->name=$_name;
$this->image=$_image;
}
}
?>

@ -12,10 +12,10 @@ class User {
public int $currentBobCoins;
public int $totalBobCoins;
public int $nbGamesPlayed;
public string $currentIdSkin;
public string $currentSkin;
public $listIdSkin;
public function __construct(string $_id,string $_username,string $_password, string $_nationality,string $_sex, string $_dateOfBirth, int $_currentBobCoins, int $_totalBobCoins, int $_nbGamesPlayed, string $_currentIdSkin, $_listIdSkin){
public function __construct(string $_id,string $_username,string $_password, string $_nationality,string $_sex, string $_dateOfBirth, int $_currentBobCoins, int $_totalBobCoins, int $_nbGamesPlayed, string $_currentSkin, $_listIdSkin){
$this->id=$_id;
$this->username=$_username;
$this->password=$_password;
@ -25,7 +25,7 @@ class User {
$this->currentBobCoins=$_currentBobCoins;
$this->totalBobCoins=$_totalBobCoins;
$this->nbGamesPlayed=$_nbGamesPlayed;
$this->currentIdSkin=$_currentIdSkin;
$this->currentSkin=$_currentSkin;
$this->listIdSkin=$_listIdSkin;
}

Loading…
Cancel
Save