From 0a6ea075b91a6c247c42dd382a8b569e78551a11 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Thu, 5 Jan 2023 16:20:13 +0100 Subject: [PATCH] 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");