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