From c9db235c3bccdfe1abbec9c60e40249dace3449b Mon Sep 17 00:00:00 2001 From: viastolfi Date: Wed, 7 Dec 2022 14:55:10 +0100 Subject: [PATCH] changement du functionnement de l'API afin de la rendre plus utilisable --- Sources/API/.htaccess | 0 Sources/API/api/inscrit/read.php | 35 ++++ Sources/API/config/Autoload.php | 32 ---- Sources/API/config/Config.php | 9 - Sources/API/config/Database.php | 22 +++ Sources/API/controller/.gitkeep | 0 Sources/API/controller/Controller.php | 177 ------------------ Sources/API/index.php | 13 -- Sources/API/modele/Connection.php | 36 ---- Sources/API/modele/MdlInscrit.php | 14 -- .../API/modele/gateways/InscritGateway.php | 17 -- Sources/API/models/Inscrit.php | 35 ++++ 12 files changed, 92 insertions(+), 298 deletions(-) delete mode 100644 Sources/API/.htaccess create mode 100644 Sources/API/api/inscrit/read.php delete mode 100644 Sources/API/config/Autoload.php delete mode 100644 Sources/API/config/Config.php create mode 100644 Sources/API/config/Database.php delete mode 100644 Sources/API/controller/.gitkeep delete mode 100644 Sources/API/controller/Controller.php delete mode 100644 Sources/API/index.php delete mode 100644 Sources/API/modele/Connection.php delete mode 100644 Sources/API/modele/MdlInscrit.php delete mode 100644 Sources/API/modele/gateways/InscritGateway.php create mode 100644 Sources/API/models/Inscrit.php diff --git a/Sources/API/.htaccess b/Sources/API/.htaccess deleted file mode 100644 index e69de29..0000000 diff --git a/Sources/API/api/inscrit/read.php b/Sources/API/api/inscrit/read.php new file mode 100644 index 0000000..7e0d36b --- /dev/null +++ b/Sources/API/api/inscrit/read.php @@ -0,0 +1,35 @@ +connect(); + $inscrit = new Inscrit($db); + + $results = $inscrit->read(); + $num = $results->rowCount(); + + if($num > 0){ + $inscrit_array = array(); + + while($row = $results->fetch(PDO::FETCH_ASSOC)){ + extract($row); + + $inscrit_item = array( + 'id' => $id, + 'nom' => $nom, + 'prenom' => $prenom, + 'mail' => $mail, + 'mdp' => $mdp + ); + array_push($inscrit_array, $inscrit_item); + } + + echo json_encode($inscrit_array); + } else { + echo json_encode(array('message' => 'No Inscrit Found')); + } +?> \ No newline at end of file diff --git a/Sources/API/config/Autoload.php b/Sources/API/config/Autoload.php deleted file mode 100644 index 10eb20c..0000000 --- a/Sources/API/config/Autoload.php +++ /dev/null @@ -1,32 +0,0 @@ -$file

"; - if(file_exists($file)){ - include $file; - } - } - } -} - -?> \ No newline at end of file diff --git a/Sources/API/config/Config.php b/Sources/API/config/Config.php deleted file mode 100644 index 5b648a6..0000000 --- a/Sources/API/config/Config.php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/Sources/API/config/Database.php b/Sources/API/config/Database.php new file mode 100644 index 0000000..cd59896 --- /dev/null +++ b/Sources/API/config/Database.php @@ -0,0 +1,22 @@ +conn = null; + + try{ + $this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->db_name, $this->username, $this->password); + $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch(PDOException $e){ + echo 'Connection Error :'.$e->getMessage(); + } + + return $this->conn; + } +} +?> \ No newline at end of file diff --git a/Sources/API/controller/.gitkeep b/Sources/API/controller/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Sources/API/controller/Controller.php b/Sources/API/controller/Controller.php deleted file mode 100644 index 81ef754..0000000 --- a/Sources/API/controller/Controller.php +++ /dev/null @@ -1,177 +0,0 @@ -executeQueryWithoutParameters($query); - - $query='INSERT INTO Devise VALUES("EUR","EURO"); - INSERT INTO Devise VALUES("USD","DOLLAR"); - INSERT INTO Devise VALUES("GBP","Livre Sterling"); - INSERT INTO Devise VALUES("JPY","YEN"); - INSERT INTO Devise VALUES("AUD","DOLLAR AUSTRALIEN"); - INSERT INTO Devise VALUES("NZD","DOLLAR NEO-ZELANDAIS"); - INSERT INTO Devise VALUES("ZAR","RANd"); - - - INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES("EVARD","LUCAS","lucasevard@gmail.com","test"); - INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES("MONCUL","STEPHANE","stef@gmail.com","teststef"); - INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES("MENFOUMETTOITOUTNU","RENAUD","renaudtoutnu@gmail.com","test000"); - INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES("YOUVOI","BENJAMIN","BENJAMIN@gmail.com","BENJAMIN"); - INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES("TUBEAU","RAOUL","raoullacouille@gmail.com","zizi"); - - INSERT INTO DeviseInscrit VALUES("EUR","1"); - INSERT INTO DeviseInscrit VALUES("JPY","2"); - INSERT INTO DeviseInscrit VALUES("USD","3"); - INSERT INTO DeviseInscrit VALUES("NZD","4"); - - - INSERT INtO Banque(nom,urlsite,urllogo) VALUES("BNP PARIBAS","mabanque","imagesitebnb.fr"); - INSERT INtO Banque(nom,urlsite,urllogo) VALUES("CREDIT AGRICOLE","credit-agricole.fr","imageca"); - INSERT INtO Banque(nom,urlsite,urllogo) VALUES("BANQUE POSTALE","labanquepostale.fr","imgbp"); - INSERT INtO Banque(nom,urlsite,urllogo) VALUES("CAISSE D EPARGNE","caisse-epargne.fr","imgcaissedepargne"); - - - INSERT INTO InscrBanque (nomBanque,idInscrit)VALUES("BNP PARIBAS","1"); - INSERT INTO InscrBanque (nomBanque,idInscrit)VALUES("CREDIT AGRICOLE","2"); - INSERT INTO InscrBanque (nomBanque,idInscrit)VALUES("BANQUE POSTALE","3"); - INSERT INTO InscrBanque (nomBanque,idInscrit)VALUES("CAISSE D EPARGNE","4"); - - - INSERT INTO Compte (nom,idInscritBanque)VALUES("LIVRET A","1"); - INSERT INTO Compte (nom,idInscritBanque)VALUES("LIVRET A","2"); - INSERT INTO Compte (nom,idInscritBanque)VALUES("LIVRET A","3"); - INSERT INTO Compte (nom,idInscritBanque)VALUES("LIVRET A","4"); - - - INSERT INTO Planification (nom,credit,compte,datep,datecrea,methodePayement) VALUES ("EDF","190","1",now(),now(),"CB"); - INSERT INTO Planification (nom,credit,compte,datep,datecrea,methodePayement) VALUES ("SPOTIFY","190","2",now(),now(),"Prélevement"); - INSERT INTO Planification (nom,credit,compte,datep,datecrea,methodePayement) VALUES ("NETFLIX","190","3",now(),now(),"Cheque"); - INSERT INTO Planification (nom,credit,compte,datep,datecrea,methodePayement) VALUES ("PLAYSTATION PLUS","190","4",now(),now(),"Espece");'; - - $con->ExecuteQueryWithoutParameters($query); - switch($url[0]){ - case "SELECT": - switch($url[1]){ - case "Inscrit": - $query = 'SELECT * FROM Inscrit'; - $con->executeQueryWithoutParameters($query); - $res = $con->getResults(); - print(json_encode($res)); - break; - } - break; - default: - echo "ERREUR"; - } - } -} - -?> \ No newline at end of file diff --git a/Sources/API/index.php b/Sources/API/index.php deleted file mode 100644 index 8ba788e..0000000 --- a/Sources/API/index.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/Sources/API/modele/Connection.php b/Sources/API/modele/Connection.php deleted file mode 100644 index 9f3b119..0000000 --- a/Sources/API/modele/Connection.php +++ /dev/null @@ -1,36 +0,0 @@ -setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -} - -/** * @param string $query - * @param array $parameters * - * @return bool Returns `true` on success, `false` otherwise -*/ - -public function executeQuery(string $query, array $parameters = []) : bool{ - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); - } - - return $this->stmt->execute(); -} - -public function getResults() : array { - return $this->stmt->fetchall(); -} - -public function executeQueryWithoutParameters($query) : bool{ - $this->stmt = parent::prepare($query); - return $this->stmt->execute(); -} -} - -?> \ No newline at end of file diff --git a/Sources/API/modele/MdlInscrit.php b/Sources/API/modele/MdlInscrit.php deleted file mode 100644 index ed71324..0000000 --- a/Sources/API/modele/MdlInscrit.php +++ /dev/null @@ -1,14 +0,0 @@ -selectAll(); - } -} - -?> \ No newline at end of file diff --git a/Sources/API/modele/gateways/InscritGateway.php b/Sources/API/modele/gateways/InscritGateway.php deleted file mode 100644 index de3bfa4..0000000 --- a/Sources/API/modele/gateways/InscritGateway.php +++ /dev/null @@ -1,17 +0,0 @@ -con=$con; - } - - public function selectAll(){ - $query="SELECT * FROM Inscrit;"; - $this->con->executeQueryWithoutParameters($query); - return $this->con->getResults(); - } -} - -?> \ No newline at end of file diff --git a/Sources/API/models/Inscrit.php b/Sources/API/models/Inscrit.php new file mode 100644 index 0000000..b55d9ed --- /dev/null +++ b/Sources/API/models/Inscrit.php @@ -0,0 +1,35 @@ +conn = $db; + } + + public function read(){ + $query = 'SELECT + i.id as id, + i.nom as nom, + i.prenom as prenom, + i.mail as mail, + i.mdp as mdp + FROM + '.$this->table.' i + ORDER BY + i.id'; + + $stmt = $this->conn->prepare($query); + $stmt->execute(); + return $stmt; + } + } + +?> \ No newline at end of file