Ajout de la Planification API
continuous-integration/drone/push Build is failing Details

pull/138/head
Hugo LIVET 2 years ago
parent 34ca7ca60f
commit 014fa79013

@ -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();
?>

@ -0,0 +1,125 @@
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use OpenApi\Annotations as OA;
/**
* @OA\Info(title="My First API", version="0.1")
*/
$app->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);
}
});
?>

@ -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();
@ -322,5 +327,70 @@ namespace Data
}
//Planifications
public static async Task<List<Planification>> GetPlanificationAsync(string id)
{
var dataBody = new Dictionary<string, string> { { "id", id } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_PLANIFICATION_COMPTE_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Planification>>(await reponse.Content.ReadAsStringAsync());
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> PostAddPlanificationInscritAsync(Compte compte, Planification planification)
{
var dataBody = new Dictionary<string, string>
{
{ "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<bool> DeletePlanificationInscritAsync(string idCompte, string nomOpe)
{
var dataBody = new Dictionary<string, string> { { "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());
}
}
}
}

@ -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();
}

@ -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<Inscrit> inscrits = new List<Inscrit>();
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<Banque> RecupererBanques(Inscrit inscrit)
{
throw new NotImplementedException();
}
public IList<Banque> 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<Compte> 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<Compte> 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<Compte> 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<Compte> RecupererEcheance(Compte compte)
{
throw new NotImplementedException();
}
//actions utilitaire
public bool TestConnexion()
{
throw new NotImplementedException();
}
}
}

@ -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)
);

@ -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;
}
}
}

@ -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<Compte> RecupererPlanification(Compte compte);

@ -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,33 @@ namespace Model
{
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;
}
}
}

@ -180,3 +180,35 @@ foreach (Operation o in operations)
{
Console.WriteLine(o);
}
Console.WriteLine("\n\n\n----Planifications----\n");
IList<Planification> 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);
}
Loading…
Cancel
Save