diff --git a/Sources/API/public/index.php b/Sources/API/public/index.php index 8e9fd6e..1a87c74 100644 --- a/Sources/API/public/index.php +++ b/Sources/API/public/index.php @@ -14,7 +14,12 @@ $app->get('/', function (Request $request, Response $response, $args) { return $response; }); +$app->get('/Inscrit/', function(Request $request, Response $response, $args){ + print('TEEEEST'); +}); + require __DIR__.'/../routes/Inscrit.php'; +require __DIR__.'/../routes/Banque.php'; $app->run(); ?> \ No newline at end of file diff --git a/Sources/API/routes/Banque.php b/Sources/API/routes/Banque.php new file mode 100644 index 0000000..1e07c0e --- /dev/null +++ b/Sources/API/routes/Banque.php @@ -0,0 +1,142 @@ +addBodyParsingMiddleware(); +$app->addRoutingMiddleware(); +$app->addErrorMiddleware(true, true, true); + +/** +* @OA\Get(path="/api/Banque", +* @OA\Response(response="200", description="Succes") +* @OA\Response(response="500", description="Bdd Error") +* ) +*/ +$app->get('/Banque/', function(Request $request, Response $response){ + $query = "SELECT * FROM Banque"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->query($query); + $inscrits = $stmt->fetchAll(PDO::FETCH_OBJ); + + $db = null; + $response->getBody()->write(json_encode($inscrits)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(200); + } catch(PDOException $e){ + $error = array("message" => $e->getMessage()); + + $response->getBody()->write(json_encode($error)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(500); + } +}); + +$app->post('/Banque/FromId/', function(Request $request, Response $response,array $args){ + $id = $request->getParsedBody()["id"]; + $query = 'SELECT * FROM Banque WHERE nom IN (SELECT nomBanque FROM InscrBanque WHERE idInscrit=:id)'; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':id', $id, PDO::PARAM_STR); + + $stmt->execute(); + $inscrit = $stmt->fetchAll(PDO::FETCH_OBJ); + + $db = null; + $response->getBody()->write(json_encode($inscrit)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(200); + } catch(PDOException $e){ + $error = array("message" => $e->getMessage()); + + $response->getBody()->write(json_encode($error)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(500); + } +}); + +$app->post('/Banque/add/', function(Request $request, Response $response, array $args){ + $nom = $request->getParsedBody()["nom"]; + $idInscrit = $request->getParsedBody()["idIscrit"]; + + $query = "INSERT INTO InscrBanque (nomBanque, idInscrit) VALUES (:nom, :idInscrit) WHERE EXISTS (SELECT nom FROM Banque WHERE nom=:nom)"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':nom', $nom, PDO::PARAM_STR); + $stmt->bindValue(':idInscrit', $idInscrit, PDO::PARAM_STR); + + $result = $stmt->execute(); + + $db = null; + $response->getBody()->write(json_encode($result)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(200); + } catch(PDOException $e){ + $error = array("message" => $e->getMessage()); + + $response->getBody()->write(json_encode($error)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(500); + } +}); + +$app->delete('/Banque/delete/', function (Request $request, Response $response, array $args) { + $nom = $request->getParsedBody()["nom"]; + $idInscrit = $request->getParsedBody()["idIscrit"]; + + $query = "DELETE FROM InscrBanque WHERE nom=:nom AND idInscrit=:idI"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':nom', $nom, PDO::PARAM_STR); + $stmt->bindValue(':idI', $idInscrit, PDO::PARAM_STR); + + $result = $stmt->execute(); + + $db = null; + $response->getBody()->write(json_encode($result)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(200); + + } catch(PDOException $e){ + $error = array("message" => $e->getMessage()); + + $response->getBody()->write(json_encode($error)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(500); + } +}); + + + +?> \ No newline at end of file diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index 7b78c05..41cdbd4 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -24,11 +24,20 @@ namespace Data private const string POST_ADD_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/add/"; private const string DELETE_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/delete/"; + //routes banque + private const string GET_BANQUES_DATA_URL = ROOT_URL + "Banque/"; + private const string POST_BANQUES_INSCRIT_DATA_URL = ROOT_URL + "Banque/FromId/"; + private const string POST_ADD_BANQUE_INSCRIT_DATA_URL = ROOT_URL + "Banque/add/"; + private const string DELETE_BANQUE_INSCRIT_DATA_URL = ROOT_URL + "Banque/delete/"; + //add all routes private static HttpClient cli = new HttpClient(); + + + //Inscrit public static async Task> GetInscritsAsync() { HttpResponseMessage reponse = await cli.GetAsync(GET_INSCRITS_DATA_URL); @@ -113,5 +122,22 @@ namespace Data } + + //Banque + public static async Task> GetBanquesAsync() + { + HttpResponseMessage reponse = await cli.GetAsync(GET_BANQUES_DATA_URL); + if (reponse.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + } + + + } } diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs index 162af67..e1313e8 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -46,15 +46,11 @@ namespace Data //actions sur les banques - public bool AjouterBanque(Banque banque) + public bool AjouterBanque(Banque banque, Inscrit inscrit) { throw new NotImplementedException(); } - public bool SupprimerBanque(Banque banque) - { - throw new NotImplementedException(); - } - public bool ModifierBanque(Banque banque) + public bool SupprimerBanque(Banque banque, Inscrit inscrit) { throw new NotImplementedException(); } diff --git a/Sources/Data/PersSQL.cs b/Sources/Data/PersSQL.cs index ea90d3b..5ea58be 100644 --- a/Sources/Data/PersSQL.cs +++ b/Sources/Data/PersSQL.cs @@ -92,15 +92,11 @@ namespace Data //actions sur les banques - public bool AjouterBanque(Banque banque) + public bool AjouterBanque(Banque banque, Inscrit inscrit) { throw new NotImplementedException(); } - public bool SupprimerBanque(Banque banque) - { - throw new NotImplementedException(); - } - public bool ModifierBanque(Banque banque) + public bool SupprimerBanque(Banque banque, Inscrit inscrit) { throw new NotImplementedException(); } diff --git a/Sources/Modele/Banque.cs b/Sources/Modele/Banque.cs index 08b003f..39f9820 100644 --- a/Sources/Modele/Banque.cs +++ b/Sources/Modele/Banque.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -27,6 +28,7 @@ namespace Model } private List listeDesComptes = new List(); + [JsonConstructor] public Banque(string nom, string urlSite, string urlLogo) { Nom = nom; @@ -72,5 +74,10 @@ namespace Model throw new KeyNotFoundException(); } + public override string ToString() + { + return Nom + " " + UrlSite + " " + UrlLogo; + } + } } \ No newline at end of file diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index 126038a..772ce1a 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -20,9 +20,8 @@ namespace Model //actions sur les banques - bool AjouterBanque(Banque banque); - bool SupprimerBanque(Banque banque); - bool ModifierBanque(Banque banque); + bool AjouterBanque(Banque banque, Inscrit inscrit); + bool SupprimerBanque(Banque banque, Inscrit inscrit); IList RecupererBanques(Inscrit inscrit); IList RecupererBanquesDisponible(); diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 98e9e7f..6ac16f7 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -30,13 +30,13 @@ foreach (Compte compte in comptes) Console.WriteLine("Test ClientAPI"); - +/* IList res = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); foreach(Inscrit i in res) { Console.WriteLine(i); } - +*/ Console.WriteLine("\n--------\n"); IList inscrit = ClientAPI.GetInscritAsync("renaudtoutnu@gmail.com").GetAwaiter().GetResult(); @@ -71,4 +71,12 @@ modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); foreach (Inscrit i in modif) { Console.WriteLine(i); +} + +Console.WriteLine("\n\n\n----Banques----\n"); + +IList banques = ClientAPI.GetBanquesAsync().GetAwaiter().GetResult(); +foreach (Banque b in banques) +{ + Console.WriteLine(b); } \ No newline at end of file