From 995a4b10eeda884a2795f45069d28f9a846e719e Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 20 Dec 2022 11:49:02 +0100 Subject: [PATCH 01/19] :sparkles: Client API --- Sources/Data/ClientAPI.cs | 93 +++++++++++++++++++ Sources/Data/Data.csproj | 1 + Sources/Data/PersLinqToPgSQL.cs | 8 +- Sources/Data/Stub.cs | 16 +++- Sources/IHM/IHM.csproj | 4 + Sources/Modele/IPersistanceManager.cs | 2 +- Sources/Modele/Inscrit.cs | 21 +++-- Sources/Modele/Model.csproj | 4 + Sources/TestFonctionnel/Program.cs | 43 +++++++++ .../TestFonctionnel/TestFonctionnel.csproj | 4 + Sources/TestsUnitaires/TestsUnitaires.csproj | 1 + 11 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 Sources/Data/ClientAPI.cs diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs new file mode 100644 index 0000000..d78f859 --- /dev/null +++ b/Sources/Data/ClientAPI.cs @@ -0,0 +1,93 @@ +using Model; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Http.Json; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Data +{ + public static class ClientAPI + { + private const string ROOT_URL = "http://82.64.164.20:8888/"; + + //routes inscrit + private const string GET_INSCRITS_DATA_URL = ROOT_URL+"Inscrit/"; + private const string POST_EMAIL_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/FromMail/"; + private const string PUT_PASSWORD_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/UpdatePassword/"; + private const string POST_ADD_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/add/"; + + //add all routes + + + private static HttpClient cli = new HttpClient(); + + public static async Task> GetInscritsAsync() + { + HttpResponseMessage reponse = await cli.GetAsync(GET_INSCRITS_DATA_URL); + if(reponse.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + } + + public static async Task> GetInscritAsync(string email) + { + var dataBody = new Dictionary { { "email", email } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_EMAIL_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 PutPasswordInscritAsync(string email, string password) + { + var dataBody = new Dictionary { { "email", email }, { "password", password } }; + HttpResponseMessage reponse = await cli.PutAsJsonAsync(PUT_PASSWORD_INSCRIT_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task PostAddInscritAsync(string nom, string prenom, string email, string password) + { + var dataBody = new Dictionary { { "nom", nom }, { "prenom", prenom }, { "email", email }, { "password", password } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_INSCRIT_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + } +} diff --git a/Sources/Data/Data.csproj b/Sources/Data/Data.csproj index 27fb33c..8ed68db 100644 --- a/Sources/Data/Data.csproj +++ b/Sources/Data/Data.csproj @@ -18,6 +18,7 @@ + diff --git a/Sources/Data/PersLinqToPgSQL.cs b/Sources/Data/PersLinqToPgSQL.cs index 591609e..1a86bbe 100644 --- a/Sources/Data/PersLinqToPgSQL.cs +++ b/Sources/Data/PersLinqToPgSQL.cs @@ -296,11 +296,11 @@ namespace LinqToPgSQL return ListeCompte; } - public List LoadBanqueId(string id) + public List LoadBanqueId(int id) { - int idnombre = Int16.Parse(id); + ; List ListeBanque = new List(); - Debug.WriteLine(idnombre); + Debug.WriteLine(id); var conn = new NpgsqlConnection(connexionBDD); Console.Out.WriteLine("Ouverture de la connection"); try @@ -314,7 +314,7 @@ namespace LinqToPgSQL Environment.Exit(-1); } NpgsqlCommand cmd = new NpgsqlCommand("select b.nom,b.urlsite,b.urllogo from banque b, inscrbanque ib, Inscrit i where ib.idinscrit =(@p) AND ib.nombanque = b.nom AND ib.idinscrit = i.id;", conn); - cmd.Parameters.AddWithValue("p", idnombre); + cmd.Parameters.AddWithValue("p", id); NpgsqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { diff --git a/Sources/Data/Stub.cs b/Sources/Data/Stub.cs index b4973f6..f77505f 100644 --- a/Sources/Data/Stub.cs +++ b/Sources/Data/Stub.cs @@ -9,14 +9,14 @@ namespace Data public Stub() { lesInscrits.Add(new Inscrit( - "1", + 1, "LIVET", "livet.hugo2003@gmail.com", "Hugo", "Bonjour63." )); } - public string GetId(string mail) + public int GetId(string mail) { foreach(Inscrit i in lesInscrits) { @@ -25,7 +25,7 @@ namespace Data return i.Id; } } - return null; + return -1; } public void SupprimerInscritBdd(Inscrit inscrit) { @@ -121,6 +121,16 @@ namespace Data { return LoadOperation.LoadOperationsFromOFX(ofx); } + + string IPersistanceManager.GetId(string mail) + { + throw new NotImplementedException(); + } + + public List LoadBanqueId(int id) + { + throw new NotImplementedException(); + } } } diff --git a/Sources/IHM/IHM.csproj b/Sources/IHM/IHM.csproj index 2121a48..b512e9e 100644 --- a/Sources/IHM/IHM.csproj +++ b/Sources/IHM/IHM.csproj @@ -100,6 +100,10 @@ + + + + diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index 47be43b..1585cc6 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -18,7 +18,7 @@ namespace Model void ChangePasswordBdd(string mail, string newMdp); string RecupMdpBdd(string mail); int CalculTotalSoldeComtpe(Inscrit user); - List LoadBanqueId(string id); + List LoadBanqueId(int id); public bool TestConnexionAsDatabase(); public List ImportBanques(); public Inscrit GetInscrit(string mail); diff --git a/Sources/Modele/Inscrit.cs b/Sources/Modele/Inscrit.cs index af5aef0..b35b993 100644 --- a/Sources/Modele/Inscrit.cs +++ b/Sources/Modele/Inscrit.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using Model; using System.Threading.Tasks; using System.ComponentModel; +using Newtonsoft.Json; namespace Model { @@ -15,8 +16,9 @@ namespace Model public event PropertyChangedEventHandler PropertyChanged; - public string Id { get; private set; } - public string Nom { get; private set; } + public int Id { get; set; } + public string Nom { get; set; } + public string Prenom { get; set; } public string Mail { @@ -36,7 +38,7 @@ namespace Model } private string mail; - public string Prenom { get; set; } + public string Mdp { @@ -78,7 +80,9 @@ namespace Model } private List lesBanques; - public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal = 0) + + [JsonConstructor] + public Inscrit(int id, string nom, string mail, string prenom, string mdp, double soldeTotal = 0) { Id = id; Nom = nom; @@ -87,13 +91,13 @@ namespace Model Mdp = mdp; SoldeTotal = soldeTotal; } - public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal, List lesbanques) + public Inscrit(int id, string nom, string mail, string prenom, string mdp, double soldeTotal, List lesbanques) : this(id, nom, mail, prenom, mdp, soldeTotal) { LesBanques = lesbanques; } - public Inscrit(string mail, string id) + public Inscrit(string mail, int id) { Prenom = "Lucas"; Mail = mail; @@ -104,7 +108,6 @@ namespace Model { LesBanques = lesbanques; } - public void ajouterBanque(Banque banque) { @@ -122,5 +125,9 @@ namespace Model Dev = devise; } + public override string ToString() + { + return Id + " " + Nom + " " + Prenom + " " + Mail + " " + Mdp; + } } } diff --git a/Sources/Modele/Model.csproj b/Sources/Modele/Model.csproj index 5e4631e..b25d8ac 100644 --- a/Sources/Modele/Model.csproj +++ b/Sources/Modele/Model.csproj @@ -17,4 +17,8 @@ 6.5 + + + + \ No newline at end of file diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index b035a56..6db5c86 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -1,6 +1,13 @@ using Data; using Model; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.Net.Http.Headers; +using System.Security.Principal; +using System.Xml.Linq; +//test OFX +/* Console.WriteLine("Test Deserializer OFX - simplifié"); IList comptes= new List(); @@ -16,4 +23,40 @@ foreach (Compte compte in comptes) { Console.WriteLine("\t\t"+operation); } +} +*/ + +//test APIClient + + +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(); +foreach (Inscrit i in inscrit) +{ + Console.WriteLine(i); +} + +Console.WriteLine("\n----Modifs----\n"); + +bool r = ClientAPI.PutPasswordInscritAsync("lucasevard@gmail.com", "CeciEstUnNouveauMdp123456789!").GetAwaiter().GetResult(); +Console.WriteLine("Changement de mdp : "+r+"\n"); + +bool rr = ClientAPI.PostAddInscritAsync("LIVET", "Hugo", "livet.hugo2003@gmail.com", "EnAvantOuiOui!0").GetAwaiter().GetResult(); +Console.WriteLine("Ajout user : " + rr + "\n"); + +Console.WriteLine("\n----Resultats----\n"); + +IList modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); +foreach (Inscrit i in modif) +{ + Console.WriteLine(i); } \ No newline at end of file diff --git a/Sources/TestFonctionnel/TestFonctionnel.csproj b/Sources/TestFonctionnel/TestFonctionnel.csproj index 3c5a859..b828247 100644 --- a/Sources/TestFonctionnel/TestFonctionnel.csproj +++ b/Sources/TestFonctionnel/TestFonctionnel.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/Sources/TestsUnitaires/TestsUnitaires.csproj b/Sources/TestsUnitaires/TestsUnitaires.csproj index 290d390..581f679 100644 --- a/Sources/TestsUnitaires/TestsUnitaires.csproj +++ b/Sources/TestsUnitaires/TestsUnitaires.csproj @@ -10,6 +10,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive From d3d1b57838843a461d132271e812b2fb41ddf00a Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 20 Dec 2022 12:22:58 +0100 Subject: [PATCH 02/19] :green_heart: MaJ CI --- Sources/Data/Data_CI.csproj | 1 + Sources/Modele/Compte.cs | 4 +--- Sources/Modele/Model_CI.csproj | 4 ++++ .../TestFonctionnel/TestFonctionnel_CI.csproj | 4 ++++ Sources/TestsUnitaires/TestUnitCompte.cs | 2 +- Sources/TestsUnitaires/TestUnitInscrit.cs | 24 +++++++++---------- .../TestsUnitaires/TestsUnitaires_CI.csproj | 1 + 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Sources/Data/Data_CI.csproj b/Sources/Data/Data_CI.csproj index d3b5f41..0403fd4 100644 --- a/Sources/Data/Data_CI.csproj +++ b/Sources/Data/Data_CI.csproj @@ -13,6 +13,7 @@ + diff --git a/Sources/Modele/Compte.cs b/Sources/Modele/Compte.cs index 4282bc4..53491e8 100644 --- a/Sources/Modele/Compte.cs +++ b/Sources/Modele/Compte.cs @@ -1,6 +1,4 @@ -using Microsoft.Maui.Graphics; -using System.Collections.Specialized; -using System.ComponentModel; +using System.ComponentModel; namespace Model { diff --git a/Sources/Modele/Model_CI.csproj b/Sources/Modele/Model_CI.csproj index bfc0f18..9356e73 100644 --- a/Sources/Modele/Model_CI.csproj +++ b/Sources/Modele/Model_CI.csproj @@ -12,4 +12,8 @@ + + + + \ No newline at end of file diff --git a/Sources/TestFonctionnel/TestFonctionnel_CI.csproj b/Sources/TestFonctionnel/TestFonctionnel_CI.csproj index d16a505..1c6488f 100644 --- a/Sources/TestFonctionnel/TestFonctionnel_CI.csproj +++ b/Sources/TestFonctionnel/TestFonctionnel_CI.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/Sources/TestsUnitaires/TestUnitCompte.cs b/Sources/TestsUnitaires/TestUnitCompte.cs index 2da618a..bb5b514 100644 --- a/Sources/TestsUnitaires/TestUnitCompte.cs +++ b/Sources/TestsUnitaires/TestUnitCompte.cs @@ -25,7 +25,7 @@ namespace TestsUnitaires public void testSupprimerBanque() { Banque bq = new Banque("Crédit Agricole", "https://creditagricole.fr", "https://yt3.ggpht.com/a/AGF-l7_mEfX2eQaGm8GefLOg5ZMRciNw-pESE3gUWg=s900-c-k-c0xffffffff-no-rj-mo"); - Inscrit i1 = new Inscrit("A1001", "Smith", "smith@gmail.com", "luke", "test20000aA", 500); + Inscrit i1 = new Inscrit(1, "Smith", "smith@gmail.com", "luke", "test20000aA", 500); Assert.NotNull(i1.LesBanques); i1.ajouterBanque(bq); Assert.Contains(bq, i1.LesBanques); diff --git a/Sources/TestsUnitaires/TestUnitInscrit.cs b/Sources/TestsUnitaires/TestUnitInscrit.cs index 646f256..1858822 100644 --- a/Sources/TestsUnitaires/TestUnitInscrit.cs +++ b/Sources/TestsUnitaires/TestUnitInscrit.cs @@ -12,9 +12,9 @@ namespace TestsUnitaires [Fact] public void testCtorInscrit() { - Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); + Inscrit i = new Inscrit(1, "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); Assert.NotNull(i); - Assert.Equal("I001", i.Id); + Assert.Equal(1, i.Id); Assert.Equal("LIVET", i.Nom); Assert.Equal("Hugo.LIVET@etu.uca.fr", i.Mail); Assert.Equal("Hugo", i.Prenom); @@ -28,9 +28,9 @@ namespace TestsUnitaires List lesBanques = new List(); Banque b = new Banque("CA", "enavantouioui.fr", "NaN.fr"); lesBanques.Add(b); - Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000, lesBanques); + Inscrit i = new Inscrit(1, "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000, lesBanques); Assert.NotNull(i); - Assert.Equal("I001", i.Id); + Assert.Equal(1, i.Id); Assert.Equal("LIVET", i.Nom); Assert.Equal("Hugo.LIVET@etu.uca.fr", i.Mail); Assert.Equal("Hugo", i.Prenom); @@ -45,7 +45,7 @@ namespace TestsUnitaires public void testAjoutBanqueInscrit() { Banque b = new Banque("CA", "enavantouioui.fr", "NaN.fr"); - Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); + Inscrit i = new Inscrit(1, "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); i.ajouterBanque(b); Assert.Contains(b, i.LesBanques); } @@ -54,7 +54,7 @@ namespace TestsUnitaires public void testSupprimerBanqueInscrit() { Banque b = new Banque("CA", "enavantouioui.fr", "NaN.fr"); - Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); + Inscrit i = new Inscrit(1, "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); i.ajouterBanque(b); i.SupprimerBanque(b); Assert.DoesNotContain(b, i.LesBanques); @@ -66,17 +66,17 @@ namespace TestsUnitaires [Fact] public void testChoixDeviseInscrit() { - Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); + Inscrit i = new Inscrit(1, "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000); i.ChoisirDevise(Devises.Euro); Assert.Equal(Devises.Euro, i.Dev); } [Theory] - [InlineData("I000001", "LIVET", "a@a.fr", "Hugo", "123Soleil@azerty", 20000, true)]//OK - [InlineData("I000002", "LIVET", "aa.fr", "Hugo", "123Soleil@azerty", 20000, false)]//Mail invalide psk pas de @ - [InlineData("I000003", "LIVET", "a@a.fr", "Hugo", "123soleil@azerty", 20000, false)]//mdp Invalide psk mdp sans Maj - [InlineData("I000004", "LIVET", "a@a.fr", "Hugo", "Soleil@azerty", 20000, false)]//mdp Invalide psk pas de chiffres - public void CtorInscrit2TU(string id, string nom, string mail, string prenom, string mdp, double solde, bool notShouldThrowException) + [InlineData(1, "LIVET", "a@a.fr", "Hugo", "123Soleil@azerty", 20000, true)]//OK + [InlineData(2, "LIVET", "aa.fr", "Hugo", "123Soleil@azerty", 20000, false)]//Mail invalide psk pas de @ + [InlineData(3, "LIVET", "a@a.fr", "Hugo", "123soleil@azerty", 20000, false)]//mdp Invalide psk mdp sans Maj + [InlineData(4, "LIVET", "a@a.fr", "Hugo", "Soleil@azerty", 20000, false)]//mdp Invalide psk pas de chiffres + public void CtorInscrit2TU(int id, string nom, string mail, string prenom, string mdp, double solde, bool notShouldThrowException) { if (!notShouldThrowException) { diff --git a/Sources/TestsUnitaires/TestsUnitaires_CI.csproj b/Sources/TestsUnitaires/TestsUnitaires_CI.csproj index eba0372..5ea16b4 100644 --- a/Sources/TestsUnitaires/TestsUnitaires_CI.csproj +++ b/Sources/TestsUnitaires/TestsUnitaires_CI.csproj @@ -10,6 +10,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive From 69ea3a08c7a17bb610392657d39340b6dbce8efd Mon Sep 17 00:00:00 2001 From: Hugo LIVET Date: Tue, 20 Dec 2022 12:25:26 +0100 Subject: [PATCH 03/19] =?UTF-8?q?:green=5Fheart:=20correction=20des=20d?= =?UTF-8?q?=C3=A9pendances=20de=20la=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.drone.yml b/.drone.yml index 253b4fd..6c3d644 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,6 +11,7 @@ steps: image: mcr.microsoft.com/dotnet/sdk:6.0 commands: - cd Sources + - dotnet add package Newtonsoft.Json --version 13.0.2 - dotnet workload restore - dotnet restore CI_MAUI.sln - dotnet build CI_MAUI.sln -c Release --no-restore @@ -28,6 +29,7 @@ steps: image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 commands: - cd Sources/ + - dotnet add package Newtonsoft.Json --version 13.0.2 - dotnet workload restore - dotnet restore CI_MAUI.sln - dotnet sonarscanner begin /k:ConsEco /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} From acb675e96a631983de0d3ee67ee5513e75dbd0d3 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 22 Dec 2022 15:26:22 +0100 Subject: [PATCH 04/19] Nouvelle IDataPersistance pas finie psk malade :( --- Sources/Data/PersAPI.cs | 148 +++++++++++++++++++ Sources/Data/PersSQL.cs | 199 ++++++++++++++++++++++++++ Sources/Data/{Stub.cs => PersStub.cs} | 4 +- Sources/Modele/IPersistanceManager.cs | 66 ++++++--- 4 files changed, 399 insertions(+), 18 deletions(-) create mode 100644 Sources/Data/PersAPI.cs create mode 100644 Sources/Data/PersSQL.cs rename Sources/Data/{Stub.cs => PersStub.cs} (98%) diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs new file mode 100644 index 0000000..472a16a --- /dev/null +++ b/Sources/Data/PersAPI.cs @@ -0,0 +1,148 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data +{ + public class PersAPI : IPersistanceManager + { + // /!\ Toutes les méthodes ici permettent d'uniquement manipuler une stratégie de persistance + // /!\ et ne doit en aucun cas manipuler la mémoire ! + + //actions sur les inscrits + public bool AjouterInscrit(Inscrit inscrit) + { + return ClientAPI.PostAddInscritAsync(inscrit.Nom, inscrit.Prenom, inscrit.Mail, inscrit.Mdp).GetAwaiter().GetResult(); + } + public bool SupprimerInscrit(Inscrit inscrit) + { + throw new NotImplementedException(); + } + public bool ModifierMdpInscrit(string mail, string nouveauMdp) + { + return ClientAPI.PutPasswordInscritAsync(mail,nouveauMdp).GetAwaiter().GetResult(); + } + public Inscrit RecupererInscrit(string mail) + { + List inscrits = ClientAPI.GetInscritAsync(mail).GetAwaiter().GetResult(); + if(inscrits.Count >= 1) + { + throw new ArgumentException("Cet email contient plusieurs utilisateurs pour la même adresse"); + } + return inscrits.FirstOrDefault(); + } + public bool EmailDisponible(string mail) + { + throw new NotImplementedException(); + } + + + //actions sur les banques + public bool AjouterBanque(Banque banque) + { + throw new NotImplementedException(); + } + public bool SupprimerBanque(Banque banque) + { + throw new NotImplementedException(); + } + public bool ModifierBanque(Banque banque) + { + throw new NotImplementedException(); + } + public IList RecupererBanques(Inscrit inscrit) + { + throw new NotImplementedException(); + } + public IList RecupererBanquesDisponible() + { + throw new NotImplementedException(); + } + + + //actions sur les comptes + public bool AjouterCompte(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerCompte(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierCompte(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererCompte(Banque banque) + { + throw new NotImplementedException(); + } + + + //actions sur les Opérations + public bool AjouterOperation(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerOperation(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierOperation(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererOperation(Compte compte) + { + throw new NotImplementedException(); + } + + + //actions sur les Planifications + public bool AjouterPlanification(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerPlanification(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierPlanification(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererPlanification(Compte compte) + { + throw new NotImplementedException(); + } + + + //actions sur les Echéances + public bool AjouterEcheance(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerEcheance(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierEcheance(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererEcheance(Compte compte) + { + throw new NotImplementedException(); + } + + + //actions utilitaire + public bool TestConnexion() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Sources/Data/PersSQL.cs b/Sources/Data/PersSQL.cs new file mode 100644 index 0000000..ea90d3b --- /dev/null +++ b/Sources/Data/PersSQL.cs @@ -0,0 +1,199 @@ +using Microsoft.Maui.ApplicationModel.Communication; +using Microsoft.Maui.Graphics; +using Model; +using Npgsql; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data +{ + public class PersSQL : IPersistanceManager + { + Hash hash = new Hash(); + private static string connexionBaseDeDonnees = String.Format("Server=2.3.8.130; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); + private static NpgsqlConnection dbAcces = new NpgsqlConnection(connexionBaseDeDonnees); + + // /!\ Toutes les méthodes ici permettent d'uniquement manipuler une stratégie de persistance + // /!\ et ne doit en aucun cas manipuler la mémoire ! + + //actions sur les inscrits + public bool AjouterInscrit(Inscrit inscrit) + { + string mdpHash = hash.CreateHashCode(inscrit.Mdp); + dbAcces.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO Inscrit (nom,prenom,mail,mdp) VALUES ((@name), (@surname), (@mail), (@password))", dbAcces) + { + Parameters = + { + new NpgsqlParameter("name", inscrit.Nom), + new NpgsqlParameter("surname", inscrit.Prenom), + new NpgsqlParameter("mail", inscrit.Mail), + new NpgsqlParameter("password", mdpHash), + } + }; + cmd.ExecuteNonQueryAsync(); + dbAcces.Close(); + return true; + } + public bool SupprimerInscrit(Inscrit inscrit) + { + dbAcces.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM INSCRIT WHERE mail=(@mail)", dbAcces) + { + Parameters = + { + new NpgsqlParameter("mail", inscrit.Mail) + } + }; + cmd.ExecuteNonQueryAsync(); + dbAcces.Close(); + return true; + } + public bool ModifierMdpInscrit(string mail, string nouveauMdp) + { + dbAcces.Open(); + using var cmd = new NpgsqlCommand($"UPDATE Inscrit SET mdp = (@mdp) WHERE mail = (@mail)", dbAcces) + { + Parameters = + { + new NpgsqlParameter("mail", mail), + new NpgsqlParameter("mdp", nouveauMdp) + } + }; + cmd.ExecuteNonQueryAsync(); + dbAcces.Close(); + return true; + + } + public Inscrit RecupererInscrit(string mail) + { + IList inscrits = new List(); + dbAcces.Open(); + NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit WHERE mail = (@mail)", dbAcces).ExecuteReader(); + while (dbReader.Read()) + { + + inscrits.Add(new Inscrit(dbReader.GetInt32(0), dbReader.GetString(1), dbReader.GetString(3), dbReader.GetString(2), dbReader.GetString(4))); + + } + dbReader.Close(); + dbAcces.Close(); + + return inscrits.FirstOrDefault(); + + } + public bool EmailDisponible(string mail) + { + throw new NotImplementedException(); + } + + + //actions sur les banques + public bool AjouterBanque(Banque banque) + { + throw new NotImplementedException(); + } + public bool SupprimerBanque(Banque banque) + { + throw new NotImplementedException(); + } + public bool ModifierBanque(Banque banque) + { + throw new NotImplementedException(); + } + public IList RecupererBanques(Inscrit inscrit) + { + throw new NotImplementedException(); + } + public IList RecupererBanquesDisponible() + { + throw new NotImplementedException(); + } + + + //actions sur les comptes + public bool AjouterCompte(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerCompte(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierCompte(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererCompte(Banque banque) + { + throw new NotImplementedException(); + } + + + //actions sur les Opérations + public bool AjouterOperation(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerOperation(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierOperation(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererOperation(Compte compte) + { + throw new NotImplementedException(); + } + + + //actions sur les Planifications + public bool AjouterPlanification(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerPlanification(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierPlanification(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererPlanification(Compte compte) + { + throw new NotImplementedException(); + } + + + //actions sur les Echéances + public bool AjouterEcheance(Compte compte) + { + throw new NotImplementedException(); + } + public bool SupprimerEcheance(Compte compte) + { + throw new NotImplementedException(); + } + public bool ModifierEcheance(Compte compte) + { + throw new NotImplementedException(); + } + public IList RecupererEcheance(Compte compte) + { + throw new NotImplementedException(); + } + + + //actions utilitaire + public bool TestConnexion() + { + throw new NotImplementedException(); + } + } +} diff --git a/Sources/Data/Stub.cs b/Sources/Data/PersStub.cs similarity index 98% rename from Sources/Data/Stub.cs rename to Sources/Data/PersStub.cs index f77505f..62b0c8c 100644 --- a/Sources/Data/Stub.cs +++ b/Sources/Data/PersStub.cs @@ -2,11 +2,11 @@ namespace Data { - public class Stub : IPersistanceManager + public class PersStub : IPersistanceManager { private List lesInscrits = new List(); - public Stub() + public PersStub() { lesInscrits.Add(new Inscrit( 1, diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index 1585cc6..126038a 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -8,21 +8,55 @@ namespace Model { public interface IPersistanceManager { - string GetId(string mail); - void SupprimerInscritBdd(Inscrit inscrit); - void SupprimerBanqueBdd(Inscrit inscrit, Banque banque); - void SupprimerToutesBanquesBdd(Inscrit inscrit); - void CreateInscrit(Inscrit inscrit); - string LastInscrit(); - bool ExistEmail(string mail); - void ChangePasswordBdd(string mail, string newMdp); - string RecupMdpBdd(string mail); - int CalculTotalSoldeComtpe(Inscrit user); - List LoadBanqueId(int id); - public bool TestConnexionAsDatabase(); - public List ImportBanques(); - public Inscrit GetInscrit(string mail); - - public IList GetCompteFromOFX(string ofx); + // /!\ Toutes les méthodes ici permettent d'uniquement manipuler une stratégie de persistance + // /!\ et ne doit en aucun cas manipuler la mémoire ! + + //actions sur les inscrits + bool AjouterInscrit(Inscrit inscrit); + bool SupprimerInscrit(Inscrit inscrit); + bool ModifierMdpInscrit(string mail, string nouveauMdp); + Inscrit RecupererInscrit(string mail); + bool EmailDisponible(string mail); + + + //actions sur les banques + bool AjouterBanque(Banque banque); + bool SupprimerBanque(Banque banque); + bool ModifierBanque(Banque banque); + IList RecupererBanques(Inscrit inscrit); + IList RecupererBanquesDisponible(); + + + //actions sur les comptes + bool AjouterCompte(Compte compte); + bool SupprimerCompte(Compte compte); + bool ModifierCompte(Compte compte); + IList RecupererCompte(Banque banque); + + + //actions sur les Opérations + bool AjouterOperation(Compte compte); + bool SupprimerOperation(Compte compte); + bool ModifierOperation(Compte compte); + IList RecupererOperation(Compte compte); + + + //actions sur les Planifications + bool AjouterPlanification(Compte compte); + bool SupprimerPlanification(Compte compte); + bool ModifierPlanification(Compte compte); + IList RecupererPlanification(Compte compte); + + + //actions sur les Echéances + bool AjouterEcheance(Compte compte); + bool SupprimerEcheance(Compte compte); + bool ModifierEcheance(Compte compte); + IList RecupererEcheance(Compte compte); + + + //actions utilitaire + bool TestConnexion(); + } } From 8889b164f8546e062d33ee843085179d75ebcaca Mon Sep 17 00:00:00 2001 From: Hugo LIVET Date: Thu, 22 Dec 2022 15:28:47 +0100 Subject: [PATCH 05/19] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6c3d644..c3b3fc6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,8 +11,8 @@ steps: image: mcr.microsoft.com/dotnet/sdk:6.0 commands: - cd Sources - - dotnet add package Newtonsoft.Json --version 13.0.2 - dotnet workload restore + - dotnet add package Newtonsoft.Json - dotnet restore CI_MAUI.sln - dotnet build CI_MAUI.sln -c Release --no-restore - dotnet publish CI_MAUI.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release @@ -29,8 +29,8 @@ steps: image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 commands: - cd Sources/ - - dotnet add package Newtonsoft.Json --version 13.0.2 - dotnet workload restore + - dotnet add package Newtonsoft.Json - dotnet restore CI_MAUI.sln - dotnet sonarscanner begin /k:ConsEco /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} - dotnet build CI_MAUI.sln -c Release --no-restore From 3963d6dbd87cd7cba6ef7f986ef0284c6cbb97b3 Mon Sep 17 00:00:00 2001 From: Hugo LIVET Date: Thu, 22 Dec 2022 15:30:38 +0100 Subject: [PATCH 06/19] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index c3b3fc6..5e9c2aa 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,9 +10,9 @@ steps: - name: build image: mcr.microsoft.com/dotnet/sdk:6.0 commands: + - dotnet add package Newtonsoft.Json - cd Sources - dotnet workload restore - - dotnet add package Newtonsoft.Json - dotnet restore CI_MAUI.sln - dotnet build CI_MAUI.sln -c Release --no-restore - dotnet publish CI_MAUI.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release @@ -28,9 +28,9 @@ steps: - name: code-analysis image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 commands: + - dotnet add package Newtonsoft.Json - cd Sources/ - dotnet workload restore - - dotnet add package Newtonsoft.Json - dotnet restore CI_MAUI.sln - dotnet sonarscanner begin /k:ConsEco /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} - dotnet build CI_MAUI.sln -c Release --no-restore From 12fefde1d7a7270a15761812c0b4568a0ef040e8 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 09:51:03 +0100 Subject: [PATCH 07/19] Ajout de Route --- Sources/API/routes/Inscrit.php | 33 ++++++++++++ Sources/Data/ClientAPI.cs | 24 +++++++++ Sources/Data/PersAPI.cs | 9 +++- Sources/Data/PersLinqToPgSQL.cs | 2 +- Sources/Data/PersStub.cs | 7 +-- Sources/IHM/Mobile/Inscription.xaml.cs | 8 +-- Sources/Modele/Manager.cs | 74 +------------------------- Sources/TestFonctionnel/Program.cs | 12 +++++ 8 files changed, 85 insertions(+), 84 deletions(-) diff --git a/Sources/API/routes/Inscrit.php b/Sources/API/routes/Inscrit.php index 54ebb12..88902fb 100644 --- a/Sources/API/routes/Inscrit.php +++ b/Sources/API/routes/Inscrit.php @@ -138,4 +138,37 @@ $app->post('/Inscrit/add/', function(Request $request, Response $response, array ->withStatus(500); } }); + + + +$app->delete('/Inscrit/delete/', function (Request $request, Response $response, array $args) { + $email = $request->getParsedBody()["email"]; + + $query = "DELETE FROM Inscrit WHERE mail=:mail"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':mail', $email, 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 d78f859..7b78c05 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -22,6 +22,7 @@ namespace Data private const string POST_EMAIL_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/FromMail/"; private const string PUT_PASSWORD_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/UpdatePassword/"; private const string POST_ADD_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/add/"; + private const string DELETE_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/delete/"; //add all routes @@ -89,5 +90,28 @@ namespace Data } + public static async Task DeleteInscritAsync(string email) + { + var dataBody = new Dictionary { { "email", email } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_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 472a16a..162af67 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -19,7 +19,7 @@ namespace Data } public bool SupprimerInscrit(Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.DeleteInscritAsync(inscrit.Mail).GetAwaiter().GetResult(); } public bool ModifierMdpInscrit(string mail, string nouveauMdp) { @@ -36,7 +36,12 @@ namespace Data } public bool EmailDisponible(string mail) { - throw new NotImplementedException(); + List inscrits = ClientAPI.GetInscritAsync(mail).GetAwaiter().GetResult(); + if (inscrits.Count >= 1) + { + return false; + } + return true; } diff --git a/Sources/Data/PersLinqToPgSQL.cs b/Sources/Data/PersLinqToPgSQL.cs index 1a86bbe..52a82a9 100644 --- a/Sources/Data/PersLinqToPgSQL.cs +++ b/Sources/Data/PersLinqToPgSQL.cs @@ -17,7 +17,7 @@ using System.Reflection.PortableExecutable; namespace LinqToPgSQL { - public class PersLinqToPgSQL : IPersistanceManager + public class PersLinqToPgSQL /*: IPersistanceManager*/ { private Hash hash = new Hash(); private static string connexionBDD = String.Format("Server=2.3.8.130; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); diff --git a/Sources/Data/PersStub.cs b/Sources/Data/PersStub.cs index 62b0c8c..e209d82 100644 --- a/Sources/Data/PersStub.cs +++ b/Sources/Data/PersStub.cs @@ -2,7 +2,7 @@ namespace Data { - public class PersStub : IPersistanceManager + public class PersStub /*: IPersistanceManager*/ { private List lesInscrits = new List(); @@ -122,10 +122,7 @@ namespace Data return LoadOperation.LoadOperationsFromOFX(ofx); } - string IPersistanceManager.GetId(string mail) - { - throw new NotImplementedException(); - } + public List LoadBanqueId(int id) { diff --git a/Sources/IHM/Mobile/Inscription.xaml.cs b/Sources/IHM/Mobile/Inscription.xaml.cs index ff425a5..3a5ddc5 100644 --- a/Sources/IHM/Mobile/Inscription.xaml.cs +++ b/Sources/IHM/Mobile/Inscription.xaml.cs @@ -20,7 +20,7 @@ public partial class Inscription : ContentPage } else { - if(EntryNewPassword.Text.Equals(EntryConfirmationPassword.Text)) { + /*if(EntryNewPassword.Text.Equals(EntryConfirmationPassword.Text)) { if (Mgr.existEmail(EntryNewMail.Text)) { AffichError("Mail existant", "un compte porte déjà cette adresse mail, veuillez en changer", "OK"); @@ -43,15 +43,15 @@ public partial class Inscription : ContentPage else { AffichError("Mot de passe de confirmation invalide", "Veuillez mettre deux mots de passe identiques", "OK"); - } + }*/ } } private void ValideCode(object sender, EventArgs e) { if (EntryCodeRecept.Text == code) { - Inscrit inscrit = new Inscrit(Mgr.lastInscrit() + 1, EntryNewName.Text, EntryNewMail.Text, EntryNewSurname.Text, EntryNewPassword.Text); - Mgr.createInscrit(inscrit); + //Inscrit inscrit = new Inscrit(Mgr.lastInscrit() + 1, EntryNewName.Text, EntryNewMail.Text, EntryNewSurname.Text, EntryNewPassword.Text); + //Mgr.createInscrit(inscrit); AffichError("compte créé", "Compte bien créé", "OK"); NavigateTo(".."); } diff --git a/Sources/Modele/Manager.cs b/Sources/Modele/Manager.cs index 0ca01b4..59e2912 100644 --- a/Sources/Modele/Manager.cs +++ b/Sources/Modele/Manager.cs @@ -79,91 +79,21 @@ namespace Model Pers = persistance; } - public void SupprimerInscritBdd(Inscrit i) - { - Pers.SupprimerInscritBdd(i); - } - - public string GetId(string mail) - { - return Pers.GetId(mail); - } - - public void LoadBanques() - { - User.LesBanques = Pers.LoadBanqueId(User.Id); - if (User.LesBanques.Count() > 0) - { - SelectedBanque = User.LesBanques[0]; - } - } - - public void supprimerToutesBanquesBdd(Inscrit inscrit) - { - Pers.SupprimerToutesBanquesBdd(inscrit); - } - - public void createInscrit(Inscrit inscrit) - { - Pers.CreateInscrit(inscrit); - } - - public string lastInscrit() - { - return Pers.LastInscrit(); - } - - public bool existEmail(string mail) - { - return Pers.ExistEmail(mail); - } - - public void changePasswordBdd(string mail, string newMdp) - { - Pers.ChangePasswordBdd(mail, newMdp); - } - - public string recupMdpBdd(string mail) - { - return Pers.RecupMdpBdd(mail); - } + public bool isEqualHash(string mdpBdd, string mdpSent) { return hash.IsEqualHash(mdpBdd, mdpSent); } - public void createUser(string mail) - { - //User = new Inscrit(mail, GetId(mail)); - User = Pers.GetInscrit(mail); - } - - public int recupTotalSolde() - { - Solde = Pers.CalculTotalSoldeComtpe(User); - return Solde; - } + public void deconnexion() { User = null; } - public bool testConnexionAsDatabase() - { - return Pers.TestConnexionAsDatabase(); - } - - public void importBanques() - { - BanquesDisponibleInApp = Pers.ImportBanques(); - } - public IList getCompteFromOFX(string ofx) - { - return Pers.GetCompteFromOFX(ofx); - } } } diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 6db5c86..98e9e7f 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -57,6 +57,18 @@ Console.WriteLine("\n----Resultats----\n"); IList modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); foreach (Inscrit i in modif) +{ + Console.WriteLine(i); +} + +Console.WriteLine("\n----Modifs----\n"); + +bool rrr = ClientAPI.DeleteInscritAsync("livet.hugo2003@gmail.com").GetAwaiter().GetResult(); +Console.WriteLine("Del user : " + rr + "\n"); + + +modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); +foreach (Inscrit i in modif) { Console.WriteLine(i); } \ No newline at end of file From 5099cf76a0f809e3c17f82ae5b105eacd83b89a1 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 17:10:50 +0100 Subject: [PATCH 08/19] Ajout des routes des banques mais bug sur l'api --- Sources/API/public/index.php | 5 + Sources/API/routes/Banque.php | 142 ++++++++++++++++++++++++++ Sources/Data/ClientAPI.cs | 26 +++++ Sources/Data/PersAPI.cs | 8 +- Sources/Data/PersSQL.cs | 8 +- Sources/Modele/Banque.cs | 9 +- Sources/Modele/IPersistanceManager.cs | 5 +- Sources/TestFonctionnel/Program.cs | 12 ++- 8 files changed, 197 insertions(+), 18 deletions(-) create mode 100644 Sources/API/routes/Banque.php 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 From c05615cf79f22f1b0507375fb8427012af250663 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 17:12:36 +0100 Subject: [PATCH 09/19] modif testFonctionnel --- Sources/TestFonctionnel/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 6ac16f7..6f36b4f 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(); From add061d7b44d0ece315bff49223a96fca5e6d882 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 17:19:19 +0100 Subject: [PATCH 10/19] Patch API --- Sources/API/public/index.php | 4 ---- Sources/API/routes/Banque.php | 2 -- Sources/API/routes/Inscrit.php | 2 -- 3 files changed, 8 deletions(-) diff --git a/Sources/API/public/index.php b/Sources/API/public/index.php index 1a87c74..273acb5 100644 --- a/Sources/API/public/index.php +++ b/Sources/API/public/index.php @@ -14,10 +14,6 @@ $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'; diff --git a/Sources/API/routes/Banque.php b/Sources/API/routes/Banque.php index 1e07c0e..728d802 100644 --- a/Sources/API/routes/Banque.php +++ b/Sources/API/routes/Banque.php @@ -8,8 +8,6 @@ use OpenApi\Annotations as OA; * @OA\Info(title="My First API", version="0.1") */ -$app = AppFactory::create(); - $app->addBodyParsingMiddleware(); $app->addRoutingMiddleware(); $app->addErrorMiddleware(true, true, true); diff --git a/Sources/API/routes/Inscrit.php b/Sources/API/routes/Inscrit.php index 88902fb..5be8ebf 100644 --- a/Sources/API/routes/Inscrit.php +++ b/Sources/API/routes/Inscrit.php @@ -8,8 +8,6 @@ use OpenApi\Annotations as OA; * @OA\Info(title="My First API", version="0.1") */ -$app = AppFactory::create(); - $app->addBodyParsingMiddleware(); $app->addRoutingMiddleware(); $app->addErrorMiddleware(true, true, true); From 74d30d252296cc476a28515bc968cc903a43f26e Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 18:11:13 +0100 Subject: [PATCH 11/19] 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 From 4e150819bce5588a34a4add10f2590e7d1c852b5 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Wed, 4 Jan 2023 14:33:29 +0100 Subject: [PATCH 12/19] API Compte OK --- Sources/API/public/index.php | 1 + Sources/API/routes/Compte.php | 116 +++++++++++++++++++++ Sources/Data/ClientAPI.cs | 66 +++++++++++- Sources/Data/PersAPI.cs | 10 +- Sources/Data/PersSQL.cs | 10 +- Sources/IHM/App.xaml.cs | 2 +- Sources/IHM/Desktop/ChangePassword.xaml.cs | 2 +- Sources/IHM/Desktop/ForgetPassword.xaml.cs | 4 +- Sources/IHM/Desktop/MainPage.xaml.cs | 4 +- Sources/IHM/Mobile/AjoutBanques.xaml.cs | 8 +- Sources/IHM/Mobile/ChangePassword.xaml.cs | 2 +- Sources/IHM/Mobile/Dashboard.xaml.cs | 4 +- Sources/IHM/Mobile/ErrorPage.xaml.cs | 4 +- Sources/IHM/Mobile/ForgetPassword.xaml.cs | 4 +- Sources/IHM/Mobile/GestionBanques.xaml.cs | 2 +- Sources/IHM/Mobile/MainPage.xaml.cs | 6 +- Sources/Modele/Compte.cs | 15 ++- Sources/Modele/IPersistanceManager.cs | 7 +- Sources/TestFonctionnel/Program.cs | 32 ++++++ Sources/TestsUnitaires/TestUnitPgSQL.cs | 5 +- 20 files changed, 256 insertions(+), 48 deletions(-) create mode 100644 Sources/API/routes/Compte.php diff --git a/Sources/API/public/index.php b/Sources/API/public/index.php index 273acb5..8deb0ff 100644 --- a/Sources/API/public/index.php +++ b/Sources/API/public/index.php @@ -16,6 +16,7 @@ $app->get('/', function (Request $request, Response $response, $args) { require __DIR__.'/../routes/Inscrit.php'; require __DIR__.'/../routes/Banque.php'; +require __DIR__.'/../routes/Compte.php'; $app->run(); ?> \ No newline at end of file diff --git a/Sources/API/routes/Compte.php b/Sources/API/routes/Compte.php new file mode 100644 index 0000000..348c6cd --- /dev/null +++ b/Sources/API/routes/Compte.php @@ -0,0 +1,116 @@ +addBodyParsingMiddleware(); +$app->addRoutingMiddleware(); +$app->addErrorMiddleware(true, true, true); + +/** +* @OA\Get(path="/api/Compte", +* @OA\Response(response="200", description="Succes") +* @OA\Response(response="500", description="Bdd Error") +* ) +*/ + +$app->post('/Compte/FromIdInscrit/', function(Request $request, Response $response,array $args){ + $idInscrit = $request->getParsedBody()["id"]; + $query = 'SELECT * FROM Compte WHERE idInscritBanque=:id'; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':id', $idInscrit, PDO::PARAM_STR); + + $stmt->execute(); + $compte = $stmt->fetchAll(PDO::FETCH_OBJ); + + $db = null; + $response->getBody()->write(json_encode($compte)); + 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('/Compte/add/', function(Request $request, Response $response, array $args){ + $nom = $request->getParsedBody()["nom"]; + $idInscrit = $request->getParsedBody()["idInscrit"]; + + $query = "INSERT INTO Compte (nom, idInscritBanque) VALUES (:nom, :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); + } +}); + +$app->delete('/Compte/delete/', function (Request $request, Response $response, array $args) { + $nom = $request->getParsedBody()["nom"]; + $idInscrit = $request->getParsedBody()["idInscrit"]; + + $query = "DELETE FROM Compte WHERE nom=:nom AND idInscritBanque=: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 bba968e..22b04e3 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -30,12 +30,15 @@ namespace Data 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 - + //routes compte + private const string POST_COMPTE_INSCRIT_DATA_URL = ROOT_URL + "Compte/FromIdInscrit/"; + private const string POST_ADD_COMPTE_INSCRIT_DATA_URL = ROOT_URL + "Compte/add/"; + private const string DELETE_COMPTE_INSCRIT_DATA_URL = ROOT_URL + "Compte/delete/"; - private static HttpClient cli = new HttpClient(); + //add all routes + private static HttpClient cli = new HttpClient(); //Inscrit public static async Task> GetInscritsAsync() @@ -193,5 +196,62 @@ namespace Data } + //Comptes + public static async Task> GetCompteAsync(string id) + { + var dataBody = new Dictionary { { "id", id } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_COMPTE_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 PostAddCompteInscritAsync(string nomCompte, string idInscrit) + { + var dataBody = new Dictionary { { "nom", nomCompte }, { "idInscrit", idInscrit } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_COMPTE_INSCRIT_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task DeleteCompteInscritAsync(string nomCompte, string idInscrit) + { + var dataBody = new Dictionary { { "nom", nomCompte }, { "idInscrit", idInscrit } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_COMPTE_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 435f922..88bcd8f 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -65,19 +65,15 @@ namespace Data //actions sur les comptes - public bool AjouterCompte(Compte compte) + public bool AjouterCompte(Compte compte, Inscrit inscrit) { throw new NotImplementedException(); } - public bool SupprimerCompte(Compte compte) + public bool SupprimerCompte(Compte compte, Inscrit inscrit) { throw new NotImplementedException(); } - public bool ModifierCompte(Compte compte) - { - throw new NotImplementedException(); - } - public IList RecupererCompte(Banque banque) + public IList RecupererCompte(Banque banque, Inscrit inscrit) { throw new NotImplementedException(); } diff --git a/Sources/Data/PersSQL.cs b/Sources/Data/PersSQL.cs index 5ea58be..bef6e50 100644 --- a/Sources/Data/PersSQL.cs +++ b/Sources/Data/PersSQL.cs @@ -111,19 +111,15 @@ namespace Data //actions sur les comptes - public bool AjouterCompte(Compte compte) + public bool AjouterCompte(Compte compte, Inscrit inscrit) { throw new NotImplementedException(); } - public bool SupprimerCompte(Compte compte) + public bool SupprimerCompte(Compte compte, Inscrit inscrit) { throw new NotImplementedException(); } - public bool ModifierCompte(Compte compte) - { - throw new NotImplementedException(); - } - public IList RecupererCompte(Banque banque) + public IList RecupererCompte(Banque banque, Inscrit inscrit) { throw new NotImplementedException(); } diff --git a/Sources/IHM/App.xaml.cs b/Sources/IHM/App.xaml.cs index ef859b9..3f5ea45 100644 --- a/Sources/IHM/App.xaml.cs +++ b/Sources/IHM/App.xaml.cs @@ -6,7 +6,7 @@ namespace IHM { public partial class App : Application { - public Manager Manager { get; set; } = new Manager(new Stub()); + public Manager Manager { get; set; } = new Manager(new PersAPI()); public App() { InitializeComponent(); diff --git a/Sources/IHM/Desktop/ChangePassword.xaml.cs b/Sources/IHM/Desktop/ChangePassword.xaml.cs index 4e98fc6..f12cc9c 100644 --- a/Sources/IHM/Desktop/ChangePassword.xaml.cs +++ b/Sources/IHM/Desktop/ChangePassword.xaml.cs @@ -26,7 +26,7 @@ public partial class ChangePassword : ContentPage } else { - Mgr.changePasswordBdd(MailUser, EntryNewMdp.Text); + //Mgr.changePasswordBdd(MailUser, EntryNewMdp.Text); AffichError("mdp changé", "mot de passe bien changé", "ok"); NavigateTo("../.."); } diff --git a/Sources/IHM/Desktop/ForgetPassword.xaml.cs b/Sources/IHM/Desktop/ForgetPassword.xaml.cs index 4cd409b..45b8ad1 100644 --- a/Sources/IHM/Desktop/ForgetPassword.xaml.cs +++ b/Sources/IHM/Desktop/ForgetPassword.xaml.cs @@ -20,7 +20,7 @@ public partial class ForgetPassword : ContentPage { AffichError("Email inconnue", "Aucun compte existant portant cette adresse mail", "OK"); } - if (Mgr.existEmail(EntryMail.Text)) + /*if (Mgr.existEmail(EntryMail.Text)) { Random generator = new Random(); code = generator.Next(0, 1000000).ToString("D6"); @@ -28,7 +28,7 @@ public partial class ForgetPassword : ContentPage ValidateReceptCode.IsVisible = true; ConnexionButton.IsEnabled = false; UpdateArc(); - } + }*/ } private async void AffichError(string s, string s1, string s2) { diff --git a/Sources/IHM/Desktop/MainPage.xaml.cs b/Sources/IHM/Desktop/MainPage.xaml.cs index f6a64b8..24ba442 100644 --- a/Sources/IHM/Desktop/MainPage.xaml.cs +++ b/Sources/IHM/Desktop/MainPage.xaml.cs @@ -20,7 +20,7 @@ public partial class MainPage : ContentPage } else { - if (Mgr.existEmail(EntryMail.Text)) + /*if (Mgr.existEmail(EntryMail.Text)) { if (Mgr.isEqualHash(Mgr.recupMdpBdd(EntryMail.Text), EntryPassworld.Text)) { @@ -35,7 +35,7 @@ public partial class MainPage : ContentPage else { AffichError("Compte inexistant", "Email ou mot de passe invalide", "OK"); - } + }*/ } } diff --git a/Sources/IHM/Mobile/AjoutBanques.xaml.cs b/Sources/IHM/Mobile/AjoutBanques.xaml.cs index e54e6fd..50011ff 100644 --- a/Sources/IHM/Mobile/AjoutBanques.xaml.cs +++ b/Sources/IHM/Mobile/AjoutBanques.xaml.cs @@ -11,7 +11,7 @@ public partial class AjoutBanques : ContentPage { InitializeComponent(); BindingContext = Mgr; - Mgr.importBanques(); + //Mgr.importBanques(); if (OperatingSystem.IsIOS()) { boutonRetour.IsVisible = true; @@ -29,12 +29,12 @@ public partial class AjoutBanques : ContentPage { if (result.FileName.EndsWith("ofx", StringComparison.OrdinalIgnoreCase)) { - IList lesComptes = Mgr.getCompteFromOFX(result.FullPath); - Debug.WriteLine(lesComptes.Count); + //IList lesComptes = Mgr.getCompteFromOFX(result.FullPath); + /*Debug.WriteLine(lesComptes.Count); foreach(Compte compte in lesComptes) { Mgr.User.LesBanques.First().AjouterCompte(compte); - } + }*/ } } diff --git a/Sources/IHM/Mobile/ChangePassword.xaml.cs b/Sources/IHM/Mobile/ChangePassword.xaml.cs index 9abed58..73dfd20 100644 --- a/Sources/IHM/Mobile/ChangePassword.xaml.cs +++ b/Sources/IHM/Mobile/ChangePassword.xaml.cs @@ -25,7 +25,7 @@ public partial class ChangePassword : ContentPage } else { - Mgr.changePasswordBdd(MailUser, EntryNewMdp.Text); + //Mgr.changePasswordBdd(MailUser, EntryNewMdp.Text); AffichError("mdp changé", "mot de passe bien changé", "ok"); NavigateTo("../.."); } diff --git a/Sources/IHM/Mobile/Dashboard.xaml.cs b/Sources/IHM/Mobile/Dashboard.xaml.cs index acd4c06..6be0d67 100644 --- a/Sources/IHM/Mobile/Dashboard.xaml.cs +++ b/Sources/IHM/Mobile/Dashboard.xaml.cs @@ -17,11 +17,11 @@ public partial class DashBoard : ContentPage } - if (!Mgr.testConnexionAsDatabase()) + /* if (!Mgr.testConnexionAsDatabase()) { loadPage(new ErrorPage()); - } + }*/ } diff --git a/Sources/IHM/Mobile/ErrorPage.xaml.cs b/Sources/IHM/Mobile/ErrorPage.xaml.cs index 711e406..7809cb6 100644 --- a/Sources/IHM/Mobile/ErrorPage.xaml.cs +++ b/Sources/IHM/Mobile/ErrorPage.xaml.cs @@ -22,10 +22,10 @@ public partial class ErrorPage : ContentPage public void conIsActive() { - while (!Mgr.testConnexionAsDatabase()) + /*while (!Mgr.testConnexionAsDatabase()) { Thread.Sleep(TIME_TEST_DB); - } + }*/ ConnexionValide(); return; diff --git a/Sources/IHM/Mobile/ForgetPassword.xaml.cs b/Sources/IHM/Mobile/ForgetPassword.xaml.cs index 4384043..69c7b15 100644 --- a/Sources/IHM/Mobile/ForgetPassword.xaml.cs +++ b/Sources/IHM/Mobile/ForgetPassword.xaml.cs @@ -20,7 +20,7 @@ public partial class ForgetPassword : ContentPage { AffichError("Email inconnue", "Aucun compte existant portant cette adresse mail", "OK"); } - if (Mgr.existEmail(EntryMail.Text)){ + /*if (Mgr.existEmail(EntryMail.Text)){ Random generator = new Random(); code = generator.Next(0, 1000000).ToString("D6"); Email.CreateMail(EntryMail.Text, code); @@ -31,7 +31,7 @@ public partial class ForgetPassword : ContentPage else { AffichError("Mail inexistant", "Aucun compte possédant cette adresse email trouvé", "OK"); - } + }*/ } private async void AffichError(string s, string s1, string s2) { diff --git a/Sources/IHM/Mobile/GestionBanques.xaml.cs b/Sources/IHM/Mobile/GestionBanques.xaml.cs index 6d1001a..04681a8 100644 --- a/Sources/IHM/Mobile/GestionBanques.xaml.cs +++ b/Sources/IHM/Mobile/GestionBanques.xaml.cs @@ -11,7 +11,7 @@ public partial class GestionBanques : ContentPage { InitializeComponent(); BindingContext= Mgr; - Mgr.LoadBanques(); + //Mgr.LoadBanques(); if (OperatingSystem.IsIOS()) { boutonRetour.IsVisible = true; diff --git a/Sources/IHM/Mobile/MainPage.xaml.cs b/Sources/IHM/Mobile/MainPage.xaml.cs index c3e55c6..8d020b6 100644 --- a/Sources/IHM/Mobile/MainPage.xaml.cs +++ b/Sources/IHM/Mobile/MainPage.xaml.cs @@ -21,7 +21,7 @@ namespace IHM.Mobile AffichError("Champ invalide", "Veuillez compléter tout les champs", "OK"); } else { - if (Mgr.existEmail(EntryMail.Text)) + /* if (Mgr.existEmail(EntryMail.Text)) { if (Mgr.isEqualHash(Mgr.recupMdpBdd(EntryMail.Text), EntryPassworld.Text)) { @@ -36,13 +36,13 @@ namespace IHM.Mobile else { AffichError("Compte inexistant", "Email ou mot de passe invalide", "OK"); - } + }*/ } } private async void ConnexionValide() { - Mgr.LoadBanques(); + //Mgr.LoadBanques(); await Navigation.PopModalAsync(); } diff --git a/Sources/Modele/Compte.cs b/Sources/Modele/Compte.cs index 53491e8..85a7bc6 100644 --- a/Sources/Modele/Compte.cs +++ b/Sources/Modele/Compte.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using Newtonsoft.Json; +using System.ComponentModel; namespace Model { @@ -24,13 +25,19 @@ namespace Model private List lesOpe = new List(); public List LesPla { get; set; } = new List(); public List LesEch { get; set; } = new List(); - public Compte(string id,string nom, double solde) + + [JsonConstructor] + public Compte(string id, string nom) { Identifiant = id; Nom = nom; - Solde = solde; + Solde = 0; DerniereModification = DateTime.Now; } + public Compte(string id,string nom, double solde) : base() + { + Solde = solde; + } public Compte(string id, string nom, double solde, List lesOpe) : base() { LesOpe = lesOpe; @@ -108,7 +115,7 @@ namespace Model public override string ToString() { - return Identifiant + " " + Nom + " " + Solde + " " + DerniereModification + "\n"; + return Identifiant + " " + Nom + " " + Solde + " " + DerniereModification; } } diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index 772ce1a..a9194cc 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -27,10 +27,9 @@ namespace Model //actions sur les comptes - bool AjouterCompte(Compte compte); - bool SupprimerCompte(Compte compte); - bool ModifierCompte(Compte compte); - IList RecupererCompte(Banque banque); + bool AjouterCompte(Compte compte, Inscrit inscrit); + bool SupprimerCompte(Compte compte, Inscrit inscrit); + IList RecupererCompte(Banque banque, Inscrit inscrit); //actions sur les Opérations diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index ceeabb1..fe18523 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -115,4 +115,36 @@ banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult(); foreach (Banque b in banquesId1) { Console.WriteLine(b); +} + +Console.WriteLine("\n\n\n----Comptes----\n"); + +IList comptes = ClientAPI.GetCompteAsync("1").GetAwaiter().GetResult(); +foreach (Compte c in comptes) +{ + Console.WriteLine(c); +} + +Console.WriteLine("\n----Modifs----\n"); + +bool rrrrrrr = ClientAPI.PostAddCompteInscritAsync("PEL","1").GetAwaiter().GetResult(); +Console.WriteLine("Add Compte for user : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); + +comptes = ClientAPI.GetCompteAsync("1").GetAwaiter().GetResult(); +foreach (Compte c in comptes) +{ + Console.WriteLine(c); +} + +rrrrrrr = ClientAPI.DeleteCompteInscritAsync("PEL", "1").GetAwaiter().GetResult(); +Console.WriteLine("Del Compte for user : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); + +comptes = ClientAPI.GetCompteAsync("1").GetAwaiter().GetResult(); +foreach (Compte c in comptes) +{ + Console.WriteLine(c); } \ No newline at end of file diff --git a/Sources/TestsUnitaires/TestUnitPgSQL.cs b/Sources/TestsUnitaires/TestUnitPgSQL.cs index 545f3a6..5f158c5 100644 --- a/Sources/TestsUnitaires/TestUnitPgSQL.cs +++ b/Sources/TestsUnitaires/TestUnitPgSQL.cs @@ -1,4 +1,5 @@ -using LinqToPgSQL; +using Data; +using LinqToPgSQL; using Model; using System; using System.Collections.Generic; @@ -13,7 +14,7 @@ namespace TestsUnitaires [Fact] public void testLoadInscrit() { - Manager m = new Manager(new PersLinqToPgSQL()); + Manager m = new Manager(new PersAPI()); //Assert.Null(m.SelectedBanque); //m.LoadInscrit("lucasevard@gmail.com", "test"); //Assert.Equal(m.SelectedInscrits, "00001"); From 0f3872e8f26e416cddef705c634ac12893a2ff03 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Wed, 4 Jan 2023 18:12:28 +0100 Subject: [PATCH 13/19] =?UTF-8?q?Ajout=20routes=20Op=C3=A9ration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/API/public/index.php | 1 + Sources/API/routes/Operation.php | 123 ++++++++++++++++++++++++++ Sources/Data/ClientAPI.cs | 69 +++++++++++++++ Sources/Data/PersAPI.cs | 14 ++- Sources/Data/PersSQL.cs | 8 +- Sources/Data/insert.sql | 16 ++-- Sources/Data/tables.sql | 40 ++++----- Sources/Modele/IPersistanceManager.cs | 5 +- Sources/Modele/Inscrit.cs | 7 -- Sources/Modele/MethodePayement.cs | 3 +- Sources/Modele/Operation.cs | 6 +- Sources/TestFonctionnel/Program.cs | 32 +++++++ 12 files changed, 262 insertions(+), 62 deletions(-) create mode 100644 Sources/API/routes/Operation.php diff --git a/Sources/API/public/index.php b/Sources/API/public/index.php index 8deb0ff..13e0dd3 100644 --- a/Sources/API/public/index.php +++ b/Sources/API/public/index.php @@ -17,6 +17,7 @@ $app->get('/', function (Request $request, Response $response, $args) { require __DIR__.'/../routes/Inscrit.php'; require __DIR__.'/../routes/Banque.php'; require __DIR__.'/../routes/Compte.php'; +require __DIR__.'/../routes/Operation.php'; $app->run(); ?> \ No newline at end of file diff --git a/Sources/API/routes/Operation.php b/Sources/API/routes/Operation.php new file mode 100644 index 0000000..f04585c --- /dev/null +++ b/Sources/API/routes/Operation.php @@ -0,0 +1,123 @@ +addBodyParsingMiddleware(); +$app->addRoutingMiddleware(); +$app->addErrorMiddleware(true, true, true); + +/** +* @OA\Get(path="/api/Operation", +* @OA\Response(response="200", description="Succes") +* @OA\Response(response="500", description="Bdd Error") +* ) +*/ + +$app->post('/Operation/FromIdCompte/', function(Request $request, Response $response,array $args){ + $idCompte = $request->getParsedBody()["id"]; + $query = 'SELECT * FROM Operation WHERE compte=:id'; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':id', $idCompte, PDO::PARAM_STR); + + $stmt->execute(); + $ope = $stmt->fetchAll(PDO::FETCH_OBJ); + + $db = null; + $response->getBody()->write(json_encode($ope)); + 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('/Operation/add/', function(Request $request, Response $response, array $args){ + $compte = $request->getParsedBody()["compte"]; + $nom = $request->getParsedBody()["nom"]; + $montant = $request->getParsedBody()["montant"]; + $dateO = $request->getParsedBody()["dateO"]; + $methodePayement = $request->getParsedBody()["methodePayement"]; + $isDebit = $request->getParsedBody()["isDebit"]; + + $query = "INSERT INTO Operation (compte, nom, montant, dateO, methodePayement, isDebit) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD;"; + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':compte', $compte, PDO::PARAM_STR); + $stmt->bindValue(':nom', $nom, PDO::PARAM_STR); + $stmt->bindValue(':montant', $montant, PDO::PARAM_STR); + $stmt->bindValue(':dateO', $dateO, PDO::PARAM_STR); + $stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR); + $stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL); + + $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('/Operation/delete/', function (Request $request, Response $response, array $args) { + $compte = $request->getParsedBody()["compte"]; + $nom = $request->getParsedBody()["nom"]; + + $query = "DELETE FROM Operation WHERE compte=:compte AND nom=:nom"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':compte', $compte, PDO::PARAM_STR); + $stmt->bindValue(':nom', $nom, 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 22b04e3..a6653f4 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -35,6 +35,10 @@ namespace Data private const string POST_ADD_COMPTE_INSCRIT_DATA_URL = ROOT_URL + "Compte/add/"; private const string DELETE_COMPTE_INSCRIT_DATA_URL = ROOT_URL + "Compte/delete/"; + //routes operation + private const string POST_OPERATION_COMPTE_DATA_URL = ROOT_URL + "Operation/FromIdCompte/"; + private const string POST_ADD_OPERATION_COMPTE_DATA_URL = ROOT_URL + "Operation/add/"; + private const string DELETE_OPERATION_COMPTE_DATA_URL = ROOT_URL + "Operation/delete/"; //add all routes @@ -253,5 +257,70 @@ namespace Data } + //Operations + public static async Task> GetOperationAsync(string id) + { + var dataBody = new Dictionary { { "id", id } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_OPERATION_COMPTE_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task PostAddOperationInscritAsync(Compte compte, Operation operation) + { + var dataBody = new Dictionary + { + { "compte", compte.Identifiant }, + { "nom", operation.IntituleOperation }, + { "montant", operation.Montant.ToString() }, + { "dateO", operation.DateOperation.ToString() }, + { "methodePayement", operation.ModePayement.ToString() }, + { "isDebit", operation.IsDebit.ToString() } + }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_OPERATION_COMPTE_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task DeleteOperationInscritAsync(string nomCompte, string nomOpe) + { + var dataBody = new Dictionary { { "compte", nomCompte }, { "nom", nomOpe } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_OPERATION_COMPTE_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 88bcd8f..6b92b15 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -67,28 +67,24 @@ namespace Data //actions sur les comptes public bool AjouterCompte(Compte compte, Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.PostAddCompteInscritAsync(compte.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult(); } public bool SupprimerCompte(Compte compte, Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.DeleteCompteInscritAsync(compte.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult(); } public IList RecupererCompte(Banque banque, Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.GetCompteAsync(inscrit.Id.ToString()).GetAwaiter().GetResult(); } //actions sur les Opérations - public bool AjouterOperation(Compte compte) - { - throw new NotImplementedException(); - } - public bool SupprimerOperation(Compte compte) + public bool AjouterOperation(Compte compte, Operation operation) { throw new NotImplementedException(); } - public bool ModifierOperation(Compte compte) + public bool SupprimerOperation(Compte compte, Operation operation) { throw new NotImplementedException(); } diff --git a/Sources/Data/PersSQL.cs b/Sources/Data/PersSQL.cs index bef6e50..cc9b9b9 100644 --- a/Sources/Data/PersSQL.cs +++ b/Sources/Data/PersSQL.cs @@ -126,15 +126,11 @@ namespace Data //actions sur les Opérations - public bool AjouterOperation(Compte compte) + public bool AjouterOperation(Compte compte, Operation operation) { throw new NotImplementedException(); } - public bool SupprimerOperation(Compte compte) - { - throw new NotImplementedException(); - } - public bool ModifierOperation(Compte compte) + public bool SupprimerOperation(Compte compte, Operation operation) { throw new NotImplementedException(); } diff --git a/Sources/Data/insert.sql b/Sources/Data/insert.sql index c296050..ef88998 100644 --- a/Sources/Data/insert.sql +++ b/Sources/Data/insert.sql @@ -7,11 +7,11 @@ 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 Inscrit (nom,prenom,mail,mdp)VALUES('EVARD','LUCAS','lucasevard@gmail.com','Azerty12345678!'); +INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES('MONCUL','STEPHANE','stef@gmail.com','Azerty12345678!'); +INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES('MENFOUMETTOITOUTNU','RENAUD','renaudtoutnu@gmail.com','Azerty12345678!'); +INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES('YOUVOI','BENJAMIN','BENJAMIN@gmail.com','Azerty12345678!'); +INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES('TUBEAU','RAOUL','raoullacouille@gmail.com','Azerty12345678!'); INSERT INTO DeviseInscrit VALUES('EUR','1'); INSERT INTO DeviseInscrit VALUES('JPY','2'); @@ -35,9 +35,3 @@ 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'); \ No newline at end of file diff --git a/Sources/Data/tables.sql b/Sources/Data/tables.sql index 2bb239c..962c0e0 100644 --- a/Sources/Data/tables.sql +++ b/Sources/Data/tables.sql @@ -62,44 +62,38 @@ CREATE TABLE Compte CREATE TABLE Echeancier ( id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, - nom varchar(40), - credit numeric, compte MEDIUMINT, - debit numeric, - dateE date, - datecrea date, + nom varchar(40), + montant numeric, + dateO date, methodePayement varchar(20), - CONSTRAINT ck_echan CHECK (methodePayement IN ('CB','Cheque','Espece','Prélevement')), - FOREIGN KEY(compte) REFERENCES Compte(id), - UNIQUE (datecrea,compte) + isDebit boolean, + CONSTRAINT ck_ech CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), + FOREIGN KEY(compte) REFERENCES Compte(id) ); CREATE TABLE Operation ( id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, - nom varchar(40), - credit numeric, compte MEDIUMINT, - debit numeric, + nom varchar(40), + montant numeric, dateO date, - datecrea date, methodePayement varchar(20), - CONSTRAINT ck_methPaye CHECK (methodePayement IN ('CB','Cheque','Espece','Prélevement')), - FOREIGN KEY(compte) REFERENCES Compte(id), - UNIQUE (datecrea,compte) + isDebit boolean, + CONSTRAINT ck_methPaye CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), + FOREIGN KEY(compte) REFERENCES Compte(id) ); CREATE TABLE Planification ( id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, - nom varchar(40), - credit numeric, compte MEDIUMINT, - debit numeric, - dateP date, - datecrea date, + nom varchar(40), + montant numeric, + dateO date, methodePayement varchar(20), - CONSTRAINT ck_planif CHECK (methodePayement IN ('CB','Cheque','Espece','Prélevement')), - FOREIGN KEY(compte) REFERENCES Compte(id), - UNIQUE (datecrea,compte) + isDebit boolean, + CONSTRAINT ck_pla CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), + FOREIGN KEY(compte) REFERENCES Compte(id) ); \ No newline at end of file diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index a9194cc..fa0c5d3 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -33,9 +33,8 @@ namespace Model //actions sur les Opérations - bool AjouterOperation(Compte compte); - bool SupprimerOperation(Compte compte); - bool ModifierOperation(Compte compte); + bool AjouterOperation(Compte compte, Operation operation); + bool SupprimerOperation(Compte compte, Operation operation); IList RecupererOperation(Compte compte); diff --git a/Sources/Modele/Inscrit.cs b/Sources/Modele/Inscrit.cs index b35b993..59c1163 100644 --- a/Sources/Modele/Inscrit.cs +++ b/Sources/Modele/Inscrit.cs @@ -97,13 +97,6 @@ namespace Model LesBanques = lesbanques; } - public Inscrit(string mail, int id) - { - Prenom = "Lucas"; - Mail = mail; - Id = id; - } - public Inscrit(List lesbanques) { LesBanques = lesbanques; diff --git a/Sources/Modele/MethodePayement.cs b/Sources/Modele/MethodePayement.cs index 7a7abb8..4aa0053 100644 --- a/Sources/Modele/MethodePayement.cs +++ b/Sources/Modele/MethodePayement.cs @@ -12,6 +12,7 @@ namespace Model Cb, Esp, Chq, - Vir + Vir, + Pre } } \ No newline at end of file diff --git a/Sources/Modele/Operation.cs b/Sources/Modele/Operation.cs index d8b229f..d847bfa 100644 --- a/Sources/Modele/Operation.cs +++ b/Sources/Modele/Operation.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -32,6 +33,7 @@ namespace Model public bool IsDebit { get; private set; } + [JsonConstructor] public Operation(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, bool isDebit=true) { IntituleOperation = intituleOperation; @@ -45,7 +47,7 @@ namespace Model public override string ToString() { - return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + "\n"; + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit; } } } \ No newline at end of file diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index fe18523..315ba68 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -147,4 +147,36 @@ comptes = ClientAPI.GetCompteAsync("1").GetAwaiter().GetResult(); foreach (Compte c in comptes) { Console.WriteLine(c); +} + +Console.WriteLine("\n\n\n----Operations----\n"); + +IList operations = ClientAPI.GetOperationAsync("1").GetAwaiter().GetResult(); +foreach (Operation o in operations) +{ + Console.WriteLine(o); +} + +Console.WriteLine("\n----Modifs----\n"); + +rrrrrrr = ClientAPI.PostAddOperationInscritAsync(new Compte("1","PEL"), new Operation("test",100,DateTime.Now,MethodePayement.Cb,true)).GetAwaiter().GetResult(); +Console.WriteLine("Add Ope On Compte : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); +operations = ClientAPI.GetOperationAsync("1").GetAwaiter().GetResult(); +foreach (Operation o in operations) +{ + Console.WriteLine(o); +} + +Console.WriteLine("\n----Modifs----\n"); + +rrrrrrr = ClientAPI.DeleteOperationInscritAsync("1", "test").GetAwaiter().GetResult(); +Console.WriteLine("Del Ope On Compte : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); +operations = ClientAPI.GetOperationAsync("1").GetAwaiter().GetResult(); +foreach (Operation o in operations) +{ + Console.WriteLine(o); } \ No newline at end of file From 34ca7ca60f01a2bd6b6b926185ad2b2a3453f6e8 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Wed, 4 Jan 2023 18:19:53 +0100 Subject: [PATCH 14/19] =?UTF-8?q?Impl=C3=A9mentation=20de=20l'api=20dans?= =?UTF-8?q?=20la=20strat=C3=A9gie=20de=20persistance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Data/ClientAPI.cs | 4 ++-- Sources/Data/PersAPI.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index a6653f4..efc7ef4 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -298,9 +298,9 @@ namespace Data } - public static async Task DeleteOperationInscritAsync(string nomCompte, string nomOpe) + public static async Task DeleteOperationInscritAsync(string idCompte, string nomOpe) { - var dataBody = new Dictionary { { "compte", nomCompte }, { "nom", nomOpe } }; + var dataBody = new Dictionary { { "compte", idCompte }, { "nom", nomOpe } }; var reponse = cli.SendAsync( diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs index 6b92b15..1417ec8 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -82,15 +82,15 @@ namespace Data //actions sur les Opérations public bool AjouterOperation(Compte compte, Operation operation) { - throw new NotImplementedException(); + return ClientAPI.PostAddOperationInscritAsync(compte,operation).GetAwaiter().GetResult(); } public bool SupprimerOperation(Compte compte, Operation operation) { - throw new NotImplementedException(); + return ClientAPI.DeleteOperationInscritAsync(compte.Identifiant, operation.IntituleOperation).GetAwaiter().GetResult(); } public IList RecupererOperation(Compte compte) { - throw new NotImplementedException(); + return ClientAPI.GetCompteAsync(compte.Identifiant).GetAwaiter().GetResult(); } From 014fa7901367026827b3f543097f20547a05a03f Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 5 Jan 2023 13:35:15 +0100 Subject: [PATCH 15/19] Ajout de la Planification API --- Sources/API/public/index.php | 1 + Sources/API/routes/Planification.php | 125 +++++++++++++++++ Sources/Data/ClientAPI.cs | 72 +++++++++- Sources/Data/PersAPI.cs | 8 +- Sources/Data/PersSQL.cs | 187 -------------------------- Sources/Data/tables.sql | 1 + Sources/Modele/Echeance.cs | 30 ++++- Sources/Modele/IPersistanceManager.cs | 5 +- Sources/Modele/Planification.cs | 34 ++++- Sources/TestFonctionnel/Program.cs | 32 +++++ 10 files changed, 295 insertions(+), 200 deletions(-) create mode 100644 Sources/API/routes/Planification.php delete mode 100644 Sources/Data/PersSQL.cs diff --git a/Sources/API/public/index.php b/Sources/API/public/index.php index 13e0dd3..2a82b6e 100644 --- a/Sources/API/public/index.php +++ b/Sources/API/public/index.php @@ -18,6 +18,7 @@ require __DIR__.'/../routes/Inscrit.php'; require __DIR__.'/../routes/Banque.php'; require __DIR__.'/../routes/Compte.php'; require __DIR__.'/../routes/Operation.php'; +require __DIR__.'/../routes/Planification.php'; $app->run(); ?> \ No newline at end of file diff --git a/Sources/API/routes/Planification.php b/Sources/API/routes/Planification.php new file mode 100644 index 0000000..f6893ed --- /dev/null +++ b/Sources/API/routes/Planification.php @@ -0,0 +1,125 @@ +addBodyParsingMiddleware(); +$app->addRoutingMiddleware(); +$app->addErrorMiddleware(true, true, true); + +/** +* @OA\Get(path="/api/Planification", +* @OA\Response(response="200", description="Succes") +* @OA\Response(response="500", description="Bdd Error") +* ) +*/ + +$app->post('/Planification/FromIdCompte/', function(Request $request, Response $response,array $args){ + $idCompte = $request->getParsedBody()["id"]; + $query = 'SELECT * FROM Planification WHERE compte=:id'; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':id', $idCompte, PDO::PARAM_STR); + + $stmt->execute(); + $ope = $stmt->fetchAll(PDO::FETCH_OBJ); + + $db = null; + $response->getBody()->write(json_encode($ope)); + 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('/Planification/add/', function(Request $request, Response $response, array $args){ + $compte = $request->getParsedBody()["compte"]; + $nom = $request->getParsedBody()["nom"]; + $montant = $request->getParsedBody()["montant"]; + $dateO = $request->getParsedBody()["dateO"]; + $methodePayement = $request->getParsedBody()["methodePayement"]; + $isDebit = $request->getParsedBody()["isDebit"]; + $freq = $request->getParsedBody()["freq"]; + + $query = "INSERT INTO Planification (compte, nom, montant, dateO, methodePayement, isDebit, frequance) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD ,:freq;"; + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':compte', $compte, PDO::PARAM_STR); + $stmt->bindValue(':nom', $nom, PDO::PARAM_STR); + $stmt->bindValue(':montant', $montant, PDO::PARAM_STR); + $stmt->bindValue(':dateO', $dateO, PDO::PARAM_STR); + $stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR); + $stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL); + $stmt->bindValue(':freq', $freq, 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('/Planification/delete/', function (Request $request, Response $response, array $args) { + $compte = $request->getParsedBody()["compte"]; + $nom = $request->getParsedBody()["nom"]; + + $query = "DELETE FROM Planification WHERE compte=:compte AND nom=:nom"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':compte', $compte, PDO::PARAM_STR); + $stmt->bindValue(':nom', $nom, 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 efc7ef4..0b1ffea 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -40,6 +40,11 @@ namespace Data private const string POST_ADD_OPERATION_COMPTE_DATA_URL = ROOT_URL + "Operation/add/"; private const string DELETE_OPERATION_COMPTE_DATA_URL = ROOT_URL + "Operation/delete/"; + //routes planification + private const string POST_PLANIFICATION_COMPTE_DATA_URL = ROOT_URL + "Planification/FromIdCompte/"; + private const string POST_ADD_PLANIFICATION_COMPTE_DATA_URL = ROOT_URL + "Planification/add/"; + private const string DELETE_PLANIFICATION_COMPTE_DATA_URL = ROOT_URL + "Planification/delete/"; + //add all routes private static HttpClient cli = new HttpClient(); @@ -321,6 +326,71 @@ namespace Data } - + + //Planifications + public static async Task> GetPlanificationAsync(string id) + { + var dataBody = new Dictionary { { "id", id } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_PLANIFICATION_COMPTE_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task PostAddPlanificationInscritAsync(Compte compte, Planification planification) + { + var dataBody = new Dictionary + { + { "compte", compte.Identifiant }, + { "nom", planification.IntituleOperation }, + { "montant", planification.Montant.ToString() }, + { "dateO", planification.DateOperation.ToString() }, + { "methodePayement", planification.ModePayement.ToString() }, + { "isDebit", planification.IsDebit.ToString() }, + { "freq", planification.Frequance.ToString() } + }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_PLANIFICATION_COMPTE_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task DeletePlanificationInscritAsync(string idCompte, string nomOpe) + { + var dataBody = new Dictionary { { "compte", idCompte }, { "nom", nomOpe } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_PLANIFICATION_COMPTE_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 1417ec8..1ad86df 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -95,15 +95,11 @@ namespace Data //actions sur les Planifications - public bool AjouterPlanification(Compte compte) + public bool AjouterPlanification(Compte compte, Planification planification) { throw new NotImplementedException(); } - public bool SupprimerPlanification(Compte compte) - { - throw new NotImplementedException(); - } - public bool ModifierPlanification(Compte compte) + public bool SupprimerPlanification(Compte compte, Planification planification) { throw new NotImplementedException(); } diff --git a/Sources/Data/PersSQL.cs b/Sources/Data/PersSQL.cs deleted file mode 100644 index cc9b9b9..0000000 --- a/Sources/Data/PersSQL.cs +++ /dev/null @@ -1,187 +0,0 @@ -using Microsoft.Maui.ApplicationModel.Communication; -using Microsoft.Maui.Graphics; -using Model; -using Npgsql; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Data -{ - public class PersSQL : IPersistanceManager - { - Hash hash = new Hash(); - private static string connexionBaseDeDonnees = String.Format("Server=2.3.8.130; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); - private static NpgsqlConnection dbAcces = new NpgsqlConnection(connexionBaseDeDonnees); - - // /!\ Toutes les méthodes ici permettent d'uniquement manipuler une stratégie de persistance - // /!\ et ne doit en aucun cas manipuler la mémoire ! - - //actions sur les inscrits - public bool AjouterInscrit(Inscrit inscrit) - { - string mdpHash = hash.CreateHashCode(inscrit.Mdp); - dbAcces.Open(); - using var cmd = new NpgsqlCommand($"INSERT INTO Inscrit (nom,prenom,mail,mdp) VALUES ((@name), (@surname), (@mail), (@password))", dbAcces) - { - Parameters = - { - new NpgsqlParameter("name", inscrit.Nom), - new NpgsqlParameter("surname", inscrit.Prenom), - new NpgsqlParameter("mail", inscrit.Mail), - new NpgsqlParameter("password", mdpHash), - } - }; - cmd.ExecuteNonQueryAsync(); - dbAcces.Close(); - return true; - } - public bool SupprimerInscrit(Inscrit inscrit) - { - dbAcces.Open(); - using var cmd = new NpgsqlCommand($"DELETE FROM INSCRIT WHERE mail=(@mail)", dbAcces) - { - Parameters = - { - new NpgsqlParameter("mail", inscrit.Mail) - } - }; - cmd.ExecuteNonQueryAsync(); - dbAcces.Close(); - return true; - } - public bool ModifierMdpInscrit(string mail, string nouveauMdp) - { - dbAcces.Open(); - using var cmd = new NpgsqlCommand($"UPDATE Inscrit SET mdp = (@mdp) WHERE mail = (@mail)", dbAcces) - { - Parameters = - { - new NpgsqlParameter("mail", mail), - new NpgsqlParameter("mdp", nouveauMdp) - } - }; - cmd.ExecuteNonQueryAsync(); - dbAcces.Close(); - return true; - - } - public Inscrit RecupererInscrit(string mail) - { - IList inscrits = new List(); - dbAcces.Open(); - NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit WHERE mail = (@mail)", dbAcces).ExecuteReader(); - while (dbReader.Read()) - { - - inscrits.Add(new Inscrit(dbReader.GetInt32(0), dbReader.GetString(1), dbReader.GetString(3), dbReader.GetString(2), dbReader.GetString(4))); - - } - dbReader.Close(); - dbAcces.Close(); - - return inscrits.FirstOrDefault(); - - } - public bool EmailDisponible(string mail) - { - throw new NotImplementedException(); - } - - - //actions sur les banques - public bool AjouterBanque(Banque banque, Inscrit inscrit) - { - throw new NotImplementedException(); - } - public bool SupprimerBanque(Banque banque, Inscrit inscrit) - { - throw new NotImplementedException(); - } - public IList RecupererBanques(Inscrit inscrit) - { - throw new NotImplementedException(); - } - public IList RecupererBanquesDisponible() - { - throw new NotImplementedException(); - } - - - //actions sur les comptes - public bool AjouterCompte(Compte compte, Inscrit inscrit) - { - throw new NotImplementedException(); - } - public bool SupprimerCompte(Compte compte, Inscrit inscrit) - { - throw new NotImplementedException(); - } - public IList RecupererCompte(Banque banque, Inscrit inscrit) - { - throw new NotImplementedException(); - } - - - //actions sur les Opérations - public bool AjouterOperation(Compte compte, Operation operation) - { - throw new NotImplementedException(); - } - public bool SupprimerOperation(Compte compte, Operation operation) - { - throw new NotImplementedException(); - } - public IList RecupererOperation(Compte compte) - { - throw new NotImplementedException(); - } - - - //actions sur les Planifications - public bool AjouterPlanification(Compte compte) - { - throw new NotImplementedException(); - } - public bool SupprimerPlanification(Compte compte) - { - throw new NotImplementedException(); - } - public bool ModifierPlanification(Compte compte) - { - throw new NotImplementedException(); - } - public IList RecupererPlanification(Compte compte) - { - throw new NotImplementedException(); - } - - - //actions sur les Echéances - public bool AjouterEcheance(Compte compte) - { - throw new NotImplementedException(); - } - public bool SupprimerEcheance(Compte compte) - { - throw new NotImplementedException(); - } - public bool ModifierEcheance(Compte compte) - { - throw new NotImplementedException(); - } - public IList RecupererEcheance(Compte compte) - { - throw new NotImplementedException(); - } - - - //actions utilitaire - public bool TestConnexion() - { - throw new NotImplementedException(); - } - } -} diff --git a/Sources/Data/tables.sql b/Sources/Data/tables.sql index 962c0e0..6d4aaf3 100644 --- a/Sources/Data/tables.sql +++ b/Sources/Data/tables.sql @@ -94,6 +94,7 @@ CREATE TABLE Planification dateO date, methodePayement varchar(20), isDebit boolean, + frequance numeric, CONSTRAINT ck_pla CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), FOREIGN KEY(compte) REFERENCES Compte(id) ); \ No newline at end of file diff --git a/Sources/Modele/Echeance.cs b/Sources/Modele/Echeance.cs index e8219d7..4309680 100644 --- a/Sources/Modele/Echeance.cs +++ b/Sources/Modele/Echeance.cs @@ -1,5 +1,7 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,5 +10,31 @@ namespace Model { public class Echeance { + + public string IntituleOperation { get; private set; } + + public double Montant { get; private set; } + + public DateTime DateOperation { get; private set; } + + public MethodePayement ModePayement { get; private set; } + + public bool IsDebit { get; private set; } + + [JsonConstructor] + public Echeance(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, bool isDebit = true) + { + IntituleOperation = intituleOperation; + Montant = montant; + DateOperation = dateOperation; + ModePayement = modePayement; + IsDebit = isDebit; + } + + public override string ToString() + { + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit; + } + } } diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index fa0c5d3..38f38bd 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -39,9 +39,8 @@ namespace Model //actions sur les Planifications - bool AjouterPlanification(Compte compte); - bool SupprimerPlanification(Compte compte); - bool ModifierPlanification(Compte compte); + bool AjouterPlanification(Compte compte, Planification planification); + bool SupprimerPlanification(Compte compte, Planification planification); IList RecupererPlanification(Compte compte); diff --git a/Sources/Modele/Planification.cs b/Sources/Modele/Planification.cs index 58b70d8..5df0a7d 100644 --- a/Sources/Modele/Planification.cs +++ b/Sources/Modele/Planification.cs @@ -1,12 +1,42 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Model { - public class Planification + public class Planification { + + public string IntituleOperation { get; private set; } + + public double Montant { get; private set; } + + public DateTime DateOperation { get; private set; } + + public int Frequance { get; private set; }//en mois ? + + public MethodePayement ModePayement { get; private set; } + + public bool IsDebit { get; private set; } + + [JsonConstructor] + public Planification(string intituleOperation, double montant, DateTime dateOperation, int frequance, MethodePayement modePayement, bool isDebit = true) + { + IntituleOperation = intituleOperation; + Montant = montant; + DateOperation = dateOperation; + Frequance = frequance; + ModePayement = modePayement; + IsDebit = isDebit; + } + + public override string ToString() + { + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Frequance; + } } } diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 315ba68..282a10d 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -179,4 +179,36 @@ operations = ClientAPI.GetOperationAsync("1").GetAwaiter().GetResult(); foreach (Operation o in operations) { Console.WriteLine(o); +} + +Console.WriteLine("\n\n\n----Planifications----\n"); + +IList planifications = ClientAPI.GetPlanificationAsync("1").GetAwaiter().GetResult(); +foreach (Planification p in planifications) +{ + Console.WriteLine(p); +} + +Console.WriteLine("\n----Modifs----\n"); + +rrrrrrr = ClientAPI.PostAddPlanificationInscritAsync(new Compte("1", "PEL"), new Planification("test", 100, DateTime.Now, 30, MethodePayement.Cb, true)).GetAwaiter().GetResult(); +Console.WriteLine("Add Pla On Compte : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); +planifications = ClientAPI.GetPlanificationAsync("1").GetAwaiter().GetResult(); +foreach (Planification p in planifications) +{ + Console.WriteLine(p); +} + +Console.WriteLine("\n----Modifs----\n"); + +rrrrrrr = ClientAPI.DeletePlanificationInscritAsync("1", "test").GetAwaiter().GetResult(); +Console.WriteLine("Del Pla On Compte : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); +planifications = ClientAPI.GetPlanificationAsync("1").GetAwaiter().GetResult(); +foreach (Planification p in planifications) +{ + Console.WriteLine(p); } \ No newline at end of file From 9f434806f1f442a4f46a6d809c8e597661dcf7e3 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 5 Jan 2023 13:59:25 +0100 Subject: [PATCH 16/19] Modification classe --- Sources/Modele/Echeance.cs | 4 +++- Sources/Modele/Operation.cs | 5 ++++- Sources/Modele/Planification.cs | 12 ++++++------ Sources/Modele/TagOperation.cs | 23 +++++++++++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 Sources/Modele/TagOperation.cs diff --git a/Sources/Modele/Echeance.cs b/Sources/Modele/Echeance.cs index 4309680..c59dc5e 100644 --- a/Sources/Modele/Echeance.cs +++ b/Sources/Modele/Echeance.cs @@ -20,15 +20,17 @@ namespace Model public MethodePayement ModePayement { get; private set; } public bool IsDebit { get; private set; } + public TagOperation Tag { get; private set; } [JsonConstructor] - public Echeance(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, bool isDebit = true) + public Echeance(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, TagOperation tag, bool isDebit = true) { IntituleOperation = intituleOperation; Montant = montant; DateOperation = dateOperation; ModePayement = modePayement; IsDebit = isDebit; + Tag = tag; } public override string ToString() diff --git a/Sources/Modele/Operation.cs b/Sources/Modele/Operation.cs index d847bfa..80852ac 100644 --- a/Sources/Modele/Operation.cs +++ b/Sources/Modele/Operation.cs @@ -33,14 +33,17 @@ namespace Model public bool IsDebit { get; private set; } + public TagOperation Tag { get; private set; } + [JsonConstructor] - public Operation(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, bool isDebit=true) + public Operation(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, TagOperation tag, bool isDebit=true) { IntituleOperation = intituleOperation; Montant = montant; DateOperation = dateOperation; ModePayement = modePayement; IsDebit = isDebit; + Tag = tag; } void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/Sources/Modele/Planification.cs b/Sources/Modele/Planification.cs index 5df0a7d..d4749df 100644 --- a/Sources/Modele/Planification.cs +++ b/Sources/Modele/Planification.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Microsoft.Maui.Controls; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -17,26 +18,25 @@ namespace Model public DateTime DateOperation { get; private set; } - public int Frequance { get; private set; }//en mois ? - public MethodePayement ModePayement { get; private set; } public bool IsDebit { get; private set; } + public TagOperation Tag { get; private set; } [JsonConstructor] - public Planification(string intituleOperation, double montant, DateTime dateOperation, int frequance, MethodePayement modePayement, bool isDebit = true) + public Planification(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, TagOperation tag, bool isDebit = true) { IntituleOperation = intituleOperation; Montant = montant; DateOperation = dateOperation; - Frequance = frequance; ModePayement = modePayement; IsDebit = isDebit; + Tag = tag; } public override string ToString() { - return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Frequance; + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Tag; } } } diff --git a/Sources/Modele/TagOperation.cs b/Sources/Modele/TagOperation.cs new file mode 100644 index 0000000..7d65332 --- /dev/null +++ b/Sources/Modele/TagOperation.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + public enum TagOperation + { + Alimentaire, + Carburant, + Habitation, + Energie, + Telephonie, + Loisir, + Restauration, + Divers, + Transport, + Transaction, + Santé + } +} From 82f94f9027b967a7ffa73fd4e12025275fd88a6b Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 5 Jan 2023 15:21:00 +0100 Subject: [PATCH 17/19] =?UTF-8?q?Impl=C3=A9mentation=20de=20l'API=20finie?= =?UTF-8?q?=20!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/API/public/index.php | 1 + Sources/API/routes/Echeance.php | 125 ++++++++++++++++++++++++++ Sources/API/routes/Operation.php | 4 +- Sources/API/routes/Planification.php | 6 +- Sources/Data/ClientAPI.cs | 92 ++++++++++++++++++- Sources/Data/LoadOperation.cs | 2 +- Sources/Data/PersAPI.cs | 30 +++---- Sources/Data/insert.sql | 5 ++ Sources/Data/tables.sql | 13 ++- Sources/Modele/Echeance.cs | 2 +- Sources/Modele/IPersistanceManager.cs | 11 ++- Sources/Modele/Operation.cs | 2 +- Sources/Modele/TagOperation.cs | 1 + Sources/TestFonctionnel/Program.cs | 38 +++++++- 14 files changed, 293 insertions(+), 39 deletions(-) create mode 100644 Sources/API/routes/Echeance.php diff --git a/Sources/API/public/index.php b/Sources/API/public/index.php index 2a82b6e..2d7ce94 100644 --- a/Sources/API/public/index.php +++ b/Sources/API/public/index.php @@ -19,6 +19,7 @@ require __DIR__.'/../routes/Banque.php'; require __DIR__.'/../routes/Compte.php'; require __DIR__.'/../routes/Operation.php'; require __DIR__.'/../routes/Planification.php'; +require __DIR__.'/../routes/Echeance.php'; $app->run(); ?> \ No newline at end of file diff --git a/Sources/API/routes/Echeance.php b/Sources/API/routes/Echeance.php new file mode 100644 index 0000000..0edf00d --- /dev/null +++ b/Sources/API/routes/Echeance.php @@ -0,0 +1,125 @@ +addBodyParsingMiddleware(); +$app->addRoutingMiddleware(); +$app->addErrorMiddleware(true, true, true); + +/** +* @OA\Get(path="/api/Echeance", +* @OA\Response(response="200", description="Succes") +* @OA\Response(response="500", description="Bdd Error") +* ) +*/ + +$app->post('/Echeance/FromIdCompte/', function(Request $request, Response $response,array $args){ + $idCompte = $request->getParsedBody()["id"]; + $query = 'SELECT * FROM Echeancier WHERE compte=:id'; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':id', $idCompte, PDO::PARAM_STR); + + $stmt->execute(); + $ope = $stmt->fetchAll(PDO::FETCH_OBJ); + + $db = null; + $response->getBody()->write(json_encode($ope)); + 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('/Echeance/add/', function(Request $request, Response $response, array $args){ + $compte = $request->getParsedBody()["compte"]; + $nom = $request->getParsedBody()["nom"]; + $montant = $request->getParsedBody()["montant"]; + $dateO = $request->getParsedBody()["dateO"]; + $methodePayement = $request->getParsedBody()["methodePayement"]; + $isDebit = $request->getParsedBody()["isDebit"]; + $tag = $request->getParsedBody()["tag"]; + + $query = "INSERT INTO Echeancier (compte, nom, montant, dateO, methodePayement, isDebit, tag) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD ,:tag;"; + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':compte', $compte, PDO::PARAM_STR); + $stmt->bindValue(':nom', $nom, PDO::PARAM_STR); + $stmt->bindValue(':montant', $montant, PDO::PARAM_STR); + $stmt->bindValue(':dateO', $dateO, PDO::PARAM_STR); + $stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR); + $stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL); + $stmt->bindValue(':tag', $tag, 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('/Echeance/delete/', function (Request $request, Response $response, array $args) { + $compte = $request->getParsedBody()["compte"]; + $nom = $request->getParsedBody()["nom"]; + + $query = "DELETE FROM Echeancier WHERE compte=:compte AND nom=:nom"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':compte', $compte, PDO::PARAM_STR); + $stmt->bindValue(':nom', $nom, 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/API/routes/Operation.php b/Sources/API/routes/Operation.php index f04585c..3d4096a 100644 --- a/Sources/API/routes/Operation.php +++ b/Sources/API/routes/Operation.php @@ -55,8 +55,9 @@ $app->post('/Operation/add/', function(Request $request, Response $response, arr $dateO = $request->getParsedBody()["dateO"]; $methodePayement = $request->getParsedBody()["methodePayement"]; $isDebit = $request->getParsedBody()["isDebit"]; + $tag = $request->getParsedBody()["tag"]; - $query = "INSERT INTO Operation (compte, nom, montant, dateO, methodePayement, isDebit) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD;"; + $query = "INSERT INTO Operation (compte, nom, montant, dateO, methodePayement, isDebit, tag) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD, :tag;"; try{ $db = new Database(); $conn = $db->connect(); @@ -68,6 +69,7 @@ $app->post('/Operation/add/', function(Request $request, Response $response, arr $stmt->bindValue(':dateO', $dateO, PDO::PARAM_STR); $stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR); $stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL); + $stmt->bindValue(':tag', $tag, PDO::PARAM_STR); $result = $stmt->execute(); diff --git a/Sources/API/routes/Planification.php b/Sources/API/routes/Planification.php index f6893ed..c753d96 100644 --- a/Sources/API/routes/Planification.php +++ b/Sources/API/routes/Planification.php @@ -55,9 +55,9 @@ $app->post('/Planification/add/', function(Request $request, Response $response, $dateO = $request->getParsedBody()["dateO"]; $methodePayement = $request->getParsedBody()["methodePayement"]; $isDebit = $request->getParsedBody()["isDebit"]; - $freq = $request->getParsedBody()["freq"]; + $tag = $request->getParsedBody()["tag"]; - $query = "INSERT INTO Planification (compte, nom, montant, dateO, methodePayement, isDebit, frequance) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD ,:freq;"; + $query = "INSERT INTO Planification (compte, nom, montant, dateO, methodePayement, isDebit, tag) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD ,:tag;"; try{ $db = new Database(); $conn = $db->connect(); @@ -69,7 +69,7 @@ $app->post('/Planification/add/', function(Request $request, Response $response, $stmt->bindValue(':dateO', $dateO, PDO::PARAM_STR); $stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR); $stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL); - $stmt->bindValue(':freq', $freq, PDO::PARAM_STR); + $stmt->bindValue(':tag', $tag, PDO::PARAM_STR); $result = $stmt->execute(); diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index 0b1ffea..a290bae 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -45,7 +45,13 @@ namespace Data private const string POST_ADD_PLANIFICATION_COMPTE_DATA_URL = ROOT_URL + "Planification/add/"; private const string DELETE_PLANIFICATION_COMPTE_DATA_URL = ROOT_URL + "Planification/delete/"; - //add all routes + //routes echeance + private const string POST_ECHEANCE_COMPTE_DATA_URL = ROOT_URL + "Echeance/FromIdCompte/"; + private const string POST_ADD_ECHEANCE_COMPTE_DATA_URL = ROOT_URL + "Echeance/add/"; + private const string DELETE_ECHEANCE_COMPTE_DATA_URL = ROOT_URL + "Echeance/delete/"; + + //routes utilitaire + private const string TEST_API_STATEMENT = ROOT_URL; private static HttpClient cli = new HttpClient(); @@ -288,7 +294,8 @@ namespace Data { "montant", operation.Montant.ToString() }, { "dateO", operation.DateOperation.ToString() }, { "methodePayement", operation.ModePayement.ToString() }, - { "isDebit", operation.IsDebit.ToString() } + { "isDebit", operation.IsDebit.ToString() }, + { "tag", operation.Tag.ToString() } }; HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_OPERATION_COMPTE_DATA_URL, dataBody); @@ -354,7 +361,7 @@ namespace Data { "dateO", planification.DateOperation.ToString() }, { "methodePayement", planification.ModePayement.ToString() }, { "isDebit", planification.IsDebit.ToString() }, - { "freq", planification.Frequance.ToString() } + { "tag", planification.Tag.ToString() } }; HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_PLANIFICATION_COMPTE_DATA_URL, dataBody); @@ -392,5 +399,84 @@ namespace Data } + + //Echeances + public static async Task> GetEcheanceAsync(string id) + { + var dataBody = new Dictionary { { "id", id } }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ECHEANCE_COMPTE_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject>(await reponse.Content.ReadAsStringAsync()); + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task PostAddEcheanceInscritAsync(Compte compte, Echeance echeance) + { + var dataBody = new Dictionary + { + { "compte", compte.Identifiant }, + { "nom", echeance.IntituleOperation }, + { "montant", echeance.Montant.ToString() }, + { "dateO", echeance.DateOperation.ToString() }, + { "methodePayement", echeance.ModePayement.ToString() }, + { "isDebit", echeance.IsDebit.ToString() }, + { "tag", echeance.Tag.ToString() } + }; + HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_ECHEANCE_COMPTE_DATA_URL, dataBody); + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + public static async Task DeleteEcheanceInscritAsync(string idCompte, string nomOpe) + { + var dataBody = new Dictionary { { "compte", idCompte }, { "nom", nomOpe } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_ECHEANCE_COMPTE_DATA_URL) + { + Content = new FormUrlEncodedContent(dataBody) + }) + .Result; + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + + //Utilitaires + public static async Task GetStateApi() + { + HttpResponseMessage reponse = await cli.GetAsync(TEST_API_STATEMENT); + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + return false; + } + } } } diff --git a/Sources/Data/LoadOperation.cs b/Sources/Data/LoadOperation.cs index 164c950..cd95fa0 100644 --- a/Sources/Data/LoadOperation.cs +++ b/Sources/Data/LoadOperation.cs @@ -99,7 +99,7 @@ namespace Data row = ""; } } - compteEnCoursDeSaisie.ajouterOperation(new Operation(intituleOperation, montant, dateOperation, modePayement, isDebit)); + compteEnCoursDeSaisie.ajouterOperation(new Operation(intituleOperation, montant, dateOperation, modePayement, TagOperation.None, isDebit)); } else { diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs index 1ad86df..baad602 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -88,50 +88,46 @@ namespace Data { return ClientAPI.DeleteOperationInscritAsync(compte.Identifiant, operation.IntituleOperation).GetAwaiter().GetResult(); } - public IList RecupererOperation(Compte compte) + public IList RecupererOperation(Compte compte) { - return ClientAPI.GetCompteAsync(compte.Identifiant).GetAwaiter().GetResult(); + return ClientAPI.GetOperationAsync(compte.Identifiant).GetAwaiter().GetResult(); } //actions sur les Planifications public bool AjouterPlanification(Compte compte, Planification planification) { - throw new NotImplementedException(); + return ClientAPI.PostAddPlanificationInscritAsync(compte, planification).GetAwaiter().GetResult(); } public bool SupprimerPlanification(Compte compte, Planification planification) { - throw new NotImplementedException(); + return ClientAPI.DeletePlanificationInscritAsync(compte.Identifiant, planification.IntituleOperation).GetAwaiter().GetResult(); } - public IList RecupererPlanification(Compte compte) + public IList RecupererPlanification(Compte compte) { - throw new NotImplementedException(); + return ClientAPI.GetPlanificationAsync(compte.Identifiant).GetAwaiter().GetResult(); } //actions sur les Echéances - public bool AjouterEcheance(Compte compte) + public bool AjouterEcheance(Compte compte, Echeance echeance) { - throw new NotImplementedException(); + return ClientAPI.PostAddEcheanceInscritAsync(compte, echeance).GetAwaiter().GetResult(); } - public bool SupprimerEcheance(Compte compte) + public bool SupprimerEcheance(Compte compte, Echeance echeance) { - throw new NotImplementedException(); + return ClientAPI.DeleteEcheanceInscritAsync(compte.Identifiant, echeance.IntituleOperation).GetAwaiter().GetResult(); } - public bool ModifierEcheance(Compte compte) + public IList RecupererEcheance(Compte compte) { - throw new NotImplementedException(); - } - public IList RecupererEcheance(Compte compte) - { - throw new NotImplementedException(); + return ClientAPI.GetEcheanceAsync(compte.Identifiant).GetAwaiter().GetResult(); } //actions utilitaire public bool TestConnexion() { - throw new NotImplementedException(); + return ClientAPI.GetStateApi().GetAwaiter().GetResult(); } } } \ No newline at end of file diff --git a/Sources/Data/insert.sql b/Sources/Data/insert.sql index ef88998..c6b69d6 100644 --- a/Sources/Data/insert.sql +++ b/Sources/Data/insert.sql @@ -23,6 +23,7 @@ INSERT INtO Banque(nom,urlsite,urllogo) VALUES('BNP PARIBAS','mabanque','imagesi 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 Banque(nom,urlsite,urllogo) VALUES('ORANGE BANK','orange.fr','cpt'); INSERT INTO InscrBanque (nomBanque,idInscrit)VALUES('BNP PARIBAS','1'); @@ -35,3 +36,7 @@ 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 `Operation` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `tag`) VALUES (NULL, '1', 'JSP MAIS JAI PAYER', '500', '2023-01-02', 'Esp', '1', 'Divers'); +INSERT INTO `Planification` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `tag`) VALUES (NULL, '1', 'FAUT QUE JE PAYE', '100', '2023-01-30', 'Vir', '1', 'Energie'); +INSERT INTO `Echeancier` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `tag`) VALUES (NULL, '1', 'FAUT PAYER VITEEEE', '50', '2023-01-06', 'Vir', '1', 'Divers'); diff --git a/Sources/Data/tables.sql b/Sources/Data/tables.sql index 6d4aaf3..ef713b7 100644 --- a/Sources/Data/tables.sql +++ b/Sources/Data/tables.sql @@ -68,7 +68,9 @@ CREATE TABLE Echeancier dateO date, methodePayement varchar(20), isDebit boolean, - CONSTRAINT ck_ech CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), + tag varchar(30), + CONSTRAINT ck_methEch CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre', 'None')), + CONSTRAINT ck_tagEch CHECK (tag IN ('Alimentaire','Carburant','Habitation','Energie','Telephonie','Loisir','Restauration','Divers','Transport','Transaction','Santé')), FOREIGN KEY(compte) REFERENCES Compte(id) ); @@ -81,7 +83,9 @@ CREATE TABLE Operation dateO date, methodePayement varchar(20), isDebit boolean, - CONSTRAINT ck_methPaye CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), + tag varchar(30), + CONSTRAINT ck_methOpe CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre', 'None')), + CONSTRAINT ck_tagOpe CHECK (tag IN ('Alimentaire','Carburant','Habitation','Energie','Telephonie','Loisir','Restauration','Divers','Transport','Transaction','Santé')), FOREIGN KEY(compte) REFERENCES Compte(id) ); @@ -94,7 +98,8 @@ CREATE TABLE Planification dateO date, methodePayement varchar(20), isDebit boolean, - frequance numeric, - CONSTRAINT ck_pla CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')), + tag varchar(30), + CONSTRAINT ck_methPla CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre', 'None')), + CONSTRAINT ck_tagPla CHECK (tag IN ('Alimentaire','Carburant','Habitation','Energie','Telephonie','Loisir','Restauration','Divers','Transport','Transaction','Santé')), FOREIGN KEY(compte) REFERENCES Compte(id) ); \ No newline at end of file diff --git a/Sources/Modele/Echeance.cs b/Sources/Modele/Echeance.cs index c59dc5e..060c5da 100644 --- a/Sources/Modele/Echeance.cs +++ b/Sources/Modele/Echeance.cs @@ -35,7 +35,7 @@ namespace Model public override string ToString() { - return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit; + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Tag; } } diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index 38f38bd..cfbd58e 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -35,20 +35,19 @@ namespace Model //actions sur les Opérations bool AjouterOperation(Compte compte, Operation operation); bool SupprimerOperation(Compte compte, Operation operation); - IList RecupererOperation(Compte compte); + IList RecupererOperation(Compte compte); //actions sur les Planifications bool AjouterPlanification(Compte compte, Planification planification); bool SupprimerPlanification(Compte compte, Planification planification); - IList RecupererPlanification(Compte compte); + IList RecupererPlanification(Compte compte); //actions sur les Echéances - bool AjouterEcheance(Compte compte); - bool SupprimerEcheance(Compte compte); - bool ModifierEcheance(Compte compte); - IList RecupererEcheance(Compte compte); + bool AjouterEcheance(Compte compte, Echeance echeance); + bool SupprimerEcheance(Compte compte, Echeance echeance); + IList RecupererEcheance(Compte compte); //actions utilitaire diff --git a/Sources/Modele/Operation.cs b/Sources/Modele/Operation.cs index 80852ac..f0b6843 100644 --- a/Sources/Modele/Operation.cs +++ b/Sources/Modele/Operation.cs @@ -50,7 +50,7 @@ namespace Model public override string ToString() { - return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit; + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Tag; } } } \ No newline at end of file diff --git a/Sources/Modele/TagOperation.cs b/Sources/Modele/TagOperation.cs index 7d65332..1718c6e 100644 --- a/Sources/Modele/TagOperation.cs +++ b/Sources/Modele/TagOperation.cs @@ -8,6 +8,7 @@ namespace Model { public enum TagOperation { + None, Alimentaire, Carburant, Habitation, diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 282a10d..732f42c 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\nEtat API : " + ClientAPI.GetStateApi().GetAwaiter().GetResult()); + Console.WriteLine("\n\n\n----Inscrits----\n"); IList res = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); @@ -159,7 +161,7 @@ foreach (Operation o in operations) Console.WriteLine("\n----Modifs----\n"); -rrrrrrr = ClientAPI.PostAddOperationInscritAsync(new Compte("1","PEL"), new Operation("test",100,DateTime.Now,MethodePayement.Cb,true)).GetAwaiter().GetResult(); +rrrrrrr = ClientAPI.PostAddOperationInscritAsync(new Compte("1","PEL"), new Operation("test",100,DateTime.Now,MethodePayement.Cb, TagOperation.Alimentaire, true)).GetAwaiter().GetResult(); Console.WriteLine("Add Ope On Compte : " + rrrrrrr + "\n"); Console.WriteLine("\n----Verif----\n"); @@ -191,7 +193,7 @@ foreach (Planification p in planifications) Console.WriteLine("\n----Modifs----\n"); -rrrrrrr = ClientAPI.PostAddPlanificationInscritAsync(new Compte("1", "PEL"), new Planification("test", 100, DateTime.Now, 30, MethodePayement.Cb, true)).GetAwaiter().GetResult(); +rrrrrrr = ClientAPI.PostAddPlanificationInscritAsync(new Compte("1", "PEL"), new Planification("test", 100, DateTime.Now, MethodePayement.Cb, TagOperation.Alimentaire, true)).GetAwaiter().GetResult(); Console.WriteLine("Add Pla On Compte : " + rrrrrrr + "\n"); Console.WriteLine("\n----Verif----\n"); @@ -211,4 +213,36 @@ planifications = ClientAPI.GetPlanificationAsync("1").GetAwaiter().GetResult(); foreach (Planification p in planifications) { Console.WriteLine(p); +} + +Console.WriteLine("\n\n\n----Echeances----\n"); + +IList echeances = ClientAPI.GetEcheanceAsync("1").GetAwaiter().GetResult(); +foreach (Echeance e in echeances) +{ + Console.WriteLine(e); +} + +Console.WriteLine("\n----Modifs----\n"); + +rrrrrrr = ClientAPI.PostAddEcheanceInscritAsync(new Compte("1", "PEL"), new Echeance("test", 100, DateTime.Now, MethodePayement.Cb, TagOperation.Alimentaire, true)).GetAwaiter().GetResult(); +Console.WriteLine("Add Ech On Compte : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); +echeances = ClientAPI.GetEcheanceAsync("1").GetAwaiter().GetResult(); +foreach (Echeance e in echeances) +{ + Console.WriteLine(e); +} + +Console.WriteLine("\n----Modifs----\n"); + +rrrrrrr = ClientAPI.DeleteEcheanceInscritAsync("1", "test").GetAwaiter().GetResult(); +Console.WriteLine("Del Ech On Compte : " + rrrrrrr + "\n"); + +Console.WriteLine("\n----Verif----\n"); +echeances = ClientAPI.GetEcheanceAsync("1").GetAwaiter().GetResult(); +foreach (Echeance e in echeances) +{ + Console.WriteLine(e); } \ No newline at end of file From 0a6ea075b91a6c247c42dd382a8b569e78551a11 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 5 Jan 2023 16:20:13 +0100 Subject: [PATCH 18/19] Modification API --- Sources/API/routes/Operation.php | 4 +++- Sources/Data/ClientAPI.cs | 9 +++++---- Sources/Data/insert.sql | 2 +- Sources/Data/tables.sql | 1 + Sources/Modele/Operation.cs | 7 +++++-- Sources/TestFonctionnel/Program.cs | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Sources/API/routes/Operation.php b/Sources/API/routes/Operation.php index 3d4096a..c0f2242 100644 --- a/Sources/API/routes/Operation.php +++ b/Sources/API/routes/Operation.php @@ -56,8 +56,9 @@ $app->post('/Operation/add/', function(Request $request, Response $response, arr $methodePayement = $request->getParsedBody()["methodePayement"]; $isDebit = $request->getParsedBody()["isDebit"]; $tag = $request->getParsedBody()["tag"]; + $fromBanque = $request->getParsedBody()["fromBanque"]; - $query = "INSERT INTO Operation (compte, nom, montant, dateO, methodePayement, isDebit, tag) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD, :tag;"; + $query = "INSERT INTO Operation (compte, nom, montant, dateO, methodePayement, isDebit, fromBanque, tag) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD, :fromBanque, :tag;"; try{ $db = new Database(); $conn = $db->connect(); @@ -70,6 +71,7 @@ $app->post('/Operation/add/', function(Request $request, Response $response, arr $stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR); $stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL); $stmt->bindValue(':tag', $tag, PDO::PARAM_STR); + $stmt->bindValue(':fromBanque', $fromBanque, PDO::PARAM_BOOL); $result = $stmt->execute(); diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index a290bae..6f9cf0b 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -287,15 +287,16 @@ namespace Data public static async Task PostAddOperationInscritAsync(Compte compte, Operation operation) { - var dataBody = new Dictionary - { - { "compte", compte.Identifiant }, + var dataBody = new Dictionary + { + { "compte", compte.Identifiant }, { "nom", operation.IntituleOperation }, { "montant", operation.Montant.ToString() }, { "dateO", operation.DateOperation.ToString() }, { "methodePayement", operation.ModePayement.ToString() }, { "isDebit", operation.IsDebit.ToString() }, - { "tag", operation.Tag.ToString() } + { "tag", operation.Tag.ToString() }, + { "fromBanque", operation.FromBanque.ToString() } }; HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_OPERATION_COMPTE_DATA_URL, dataBody); diff --git a/Sources/Data/insert.sql b/Sources/Data/insert.sql index c6b69d6..7c740e7 100644 --- a/Sources/Data/insert.sql +++ b/Sources/Data/insert.sql @@ -37,6 +37,6 @@ 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 `Operation` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `tag`) VALUES (NULL, '1', 'JSP MAIS JAI PAYER', '500', '2023-01-02', 'Esp', '1', 'Divers'); +INSERT INTO `Operation` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `fromBanque`, `tag`) VALUES (NULL, '1', 'JSP MAIS JAI PAYER', '500', '2023-01-02', 'Vir', '1', '1', 'Divers') INSERT INTO `Planification` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `tag`) VALUES (NULL, '1', 'FAUT QUE JE PAYE', '100', '2023-01-30', 'Vir', '1', 'Energie'); INSERT INTO `Echeancier` (`id`, `compte`, `nom`, `montant`, `dateO`, `methodePayement`, `isDebit`, `tag`) VALUES (NULL, '1', 'FAUT PAYER VITEEEE', '50', '2023-01-06', 'Vir', '1', 'Divers'); diff --git a/Sources/Data/tables.sql b/Sources/Data/tables.sql index ef713b7..215b992 100644 --- a/Sources/Data/tables.sql +++ b/Sources/Data/tables.sql @@ -83,6 +83,7 @@ CREATE TABLE Operation dateO date, methodePayement varchar(20), isDebit boolean, + fromBanque boolean, tag varchar(30), CONSTRAINT ck_methOpe CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre', 'None')), CONSTRAINT ck_tagOpe CHECK (tag IN ('Alimentaire','Carburant','Habitation','Energie','Telephonie','Loisir','Restauration','Divers','Transport','Transaction','Santé')), diff --git a/Sources/Modele/Operation.cs b/Sources/Modele/Operation.cs index f0b6843..38dcab4 100644 --- a/Sources/Modele/Operation.cs +++ b/Sources/Modele/Operation.cs @@ -35,8 +35,10 @@ namespace Model public TagOperation Tag { get; private set; } + public bool FromBanque { get; private set; } + [JsonConstructor] - public Operation(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, TagOperation tag, bool isDebit=true) + public Operation(string intituleOperation, double montant, DateTime dateOperation, MethodePayement modePayement, TagOperation tag, bool fromBanque, bool isDebit=true) { IntituleOperation = intituleOperation; Montant = montant; @@ -44,13 +46,14 @@ namespace Model ModePayement = modePayement; IsDebit = isDebit; Tag = tag; + FromBanque = fromBanque; } void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public override string ToString() { - return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Tag; + return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + FromBanque + " " + Tag; } } } \ No newline at end of file diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 732f42c..2b7cc59 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -161,7 +161,7 @@ foreach (Operation o in operations) Console.WriteLine("\n----Modifs----\n"); -rrrrrrr = ClientAPI.PostAddOperationInscritAsync(new Compte("1","PEL"), new Operation("test",100,DateTime.Now,MethodePayement.Cb, TagOperation.Alimentaire, true)).GetAwaiter().GetResult(); +rrrrrrr = ClientAPI.PostAddOperationInscritAsync(new Compte("1","PEL"), new Operation("test",100,DateTime.Now,MethodePayement.Cb, TagOperation.Alimentaire, true, true)).GetAwaiter().GetResult(); Console.WriteLine("Add Ope On Compte : " + rrrrrrr + "\n"); Console.WriteLine("\n----Verif----\n"); From bc7c834b5a2f78463e478e1ee121fa6eb0da544b Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 5 Jan 2023 16:29:47 +0100 Subject: [PATCH 19/19] Modif Fusion --- Sources/Data/PersStub.cs | 4 ++-- Sources/TestsUnitaires/TestUnitCompte.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Data/PersStub.cs b/Sources/Data/PersStub.cs index 6f2b2ca..57a6162 100644 --- a/Sources/Data/PersStub.cs +++ b/Sources/Data/PersStub.cs @@ -63,10 +63,10 @@ namespace Data public void CreateInscrit(Inscrit inscrit){ lesInscrits.Add(inscrit); } - public string LastInscrit() + /*public string LastInscrit() { return lesInscrits[lesInscrits.Count - 1].Id; - } + }*/ public bool ExistEmail(string mail) { foreach(Inscrit i in lesInscrits) diff --git a/Sources/TestsUnitaires/TestUnitCompte.cs b/Sources/TestsUnitaires/TestUnitCompte.cs index 41312ec..3fbb1af 100644 --- a/Sources/TestsUnitaires/TestUnitCompte.cs +++ b/Sources/TestsUnitaires/TestUnitCompte.cs @@ -25,7 +25,7 @@ namespace TestsUnitaires public void TestConstructeurCompte2() { List testlistope = new(); - Operation testope = new("test", 20, DateTime.Now, MethodePayement.Cb); + Operation testope = new("test", 20, DateTime.Now, MethodePayement.Cb, TagOperation.Alimentaire, true, true); testlistope.Add(testope); Compte c1 = new("012345678901", "Livret A", 234,testlistope); Compte c2 = new("012345678902", "&e23R_te7", 1245.34, testlistope); @@ -48,7 +48,7 @@ namespace TestsUnitaires public void testAjouterOperation() { Compte c1 = new("012345678901", "Livret A", 234); - c1.ajouterOperation(new("test", 20, DateTime.Now, MethodePayement.Cb)); + c1.ajouterOperation(new("test", 20, DateTime.Now, MethodePayement.Cb, TagOperation.Alimentaire, true, true)); Assert.True(c1.LesOpe.Count() == 1); } @@ -56,7 +56,7 @@ namespace TestsUnitaires public void testSupprimerOperation() { Compte c1 = new("012345678901", "Livret A", 234); - Operation testope = new("test", 20, DateTime.Now, MethodePayement.Cb); + Operation testope = new("test", 20, DateTime.Now, MethodePayement.Cb, TagOperation.Alimentaire, true, true); c1.ajouterOperation(testope); Assert.True(c1.LesOpe.Count() == 1); c1.supprimerOperation(testope);