From 74d30d252296cc476a28515bc968cc903a43f26e Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 18:11:13 +0100 Subject: [PATCH] Ajout des routes des banques --- Sources/API/routes/Banque.php | 10 +++--- Sources/Data/ClientAPI.cs | 54 ++++++++++++++++++++++++++++++ Sources/Data/PersAPI.cs | 8 ++--- Sources/TestFonctionnel/Program.cs | 38 ++++++++++++++++++++- 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/Sources/API/routes/Banque.php b/Sources/API/routes/Banque.php index 728d802..9d7ce97 100644 --- a/Sources/API/routes/Banque.php +++ b/Sources/API/routes/Banque.php @@ -74,9 +74,9 @@ $app->post('/Banque/FromId/', function(Request $request, Response $response,arra $app->post('/Banque/add/', function(Request $request, Response $response, array $args){ $nom = $request->getParsedBody()["nom"]; - $idInscrit = $request->getParsedBody()["idIscrit"]; + $idInscrit = $request->getParsedBody()["idInscrit"]; - $query = "INSERT INTO InscrBanque (nomBanque, idInscrit) VALUES (:nom, :idInscrit) WHERE EXISTS (SELECT nom FROM Banque WHERE nom=:nom)"; + $query = "INSERT INTO InscrBanque (nomBanque, idInscrit) VALUES (:nom, :idI)"; try{ $db = new Database(); @@ -84,7 +84,7 @@ $app->post('/Banque/add/', function(Request $request, Response $response, array $stmt = $conn->prepare($query); $stmt->bindValue(':nom', $nom, PDO::PARAM_STR); - $stmt->bindValue(':idInscrit', $idInscrit, PDO::PARAM_STR); + $stmt->bindValue(':idI', $idInscrit, PDO::PARAM_STR); $result = $stmt->execute(); @@ -105,9 +105,9 @@ $app->post('/Banque/add/', function(Request $request, Response $response, array $app->delete('/Banque/delete/', function (Request $request, Response $response, array $args) { $nom = $request->getParsedBody()["nom"]; - $idInscrit = $request->getParsedBody()["idIscrit"]; + $idInscrit = $request->getParsedBody()["idInscrit"]; - $query = "DELETE FROM InscrBanque WHERE nom=:nom AND idInscrit=:idI"; + $query = "DELETE FROM InscrBanque WHERE nomBanque=:nom AND idInscrit=:idI"; try{ $db = new Database(); diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index 41cdbd4..bba968e 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -137,6 +137,60 @@ namespace Data } } + public static async Task> GetBanqueAsync(string id) + { + var dataBody = new Dictionary { { "id", id } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_BANQUES_INSCRIT_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task PostAddBanqueInscritAsync(string nomBanque, string idInscrit) + { + var dataBody = new Dictionary { { "nom", nomBanque }, { "idInscrit", idInscrit } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_BANQUE_INSCRIT_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task DeleteBanqueInscritAsync(string nomBanque, string idInscrit) + { + var dataBody = new Dictionary { { "nom", nomBanque }, { "idInscrit", idInscrit } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_BANQUE_INSCRIT_DATA_URL) + { + Content = new FormUrlEncodedContent(dataBody) + }) + .Result; + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } } diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs index e1313e8..435f922 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -48,19 +48,19 @@ namespace Data //actions sur les banques public bool AjouterBanque(Banque banque, Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.PostAddBanqueInscritAsync(banque.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult(); } public bool SupprimerBanque(Banque banque, Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.DeleteBanqueInscritAsync(banque.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult(); } public IList RecupererBanques(Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.GetBanqueAsync(inscrit.Id.ToString()).GetAwaiter().GetResult(); } public IList RecupererBanquesDisponible() { - throw new NotImplementedException(); + return ClientAPI.GetBanquesAsync().GetAwaiter().GetResult(); } diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 6f36b4f..ceeabb1 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -31,6 +31,8 @@ foreach (Compte compte in comptes) Console.WriteLine("Test ClientAPI"); +Console.WriteLine("\n\n\n----Inscrits----\n"); + IList res = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); foreach(Inscrit i in res) { @@ -64,7 +66,7 @@ foreach (Inscrit i in modif) Console.WriteLine("\n----Modifs----\n"); bool rrr = ClientAPI.DeleteInscritAsync("livet.hugo2003@gmail.com").GetAwaiter().GetResult(); -Console.WriteLine("Del user : " + rr + "\n"); +Console.WriteLine("Del user : " + rrr + "\n"); modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); @@ -77,6 +79,40 @@ Console.WriteLine("\n\n\n----Banques----\n"); IList banques = ClientAPI.GetBanquesAsync().GetAwaiter().GetResult(); foreach (Banque b in banques) +{ + Console.WriteLine(b); +} + +Console.WriteLine("\n--------\n"); + +IList banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); +foreach (Banque b in banquesId1) +{ + Console.WriteLine(b); +} + +Console.WriteLine("\n----Modifs----\n"); + +bool rrrr = ClientAPI.PostAddBanqueInscritAsync("ORANGE BANK","1").GetAwaiter().GetResult(); +Console.WriteLine("Add banque for user : " + rrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); + +banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); +foreach (Banque b in banquesId1) +{ + Console.WriteLine(b); +} + +Console.WriteLine("\n----Modifs----\n"); + +bool rrrrrr = ClientAPI.DeleteBanqueInscritAsync("ORANGE BANK", "1").GetAwaiter().GetResult(); +Console.WriteLine("Del banque for user : " + rrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); + +banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); +foreach (Banque b in banquesId1) { Console.WriteLine(b); } \ No newline at end of file