Implémentation de l'API finie !!
continuous-integration/drone/push Build is failing Details

pull/138/head
Hugo LIVET 2 years ago
parent 9f434806f1
commit 82f94f9027

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

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

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

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

@ -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<List<Echeance>> GetEcheanceAsync(string id)
{
var dataBody = new Dictionary<string, string> { { "id", id } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ECHEANCE_COMPTE_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Echeance>>(await reponse.Content.ReadAsStringAsync());
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> PostAddEcheanceInscritAsync(Compte compte, Echeance echeance)
{
var dataBody = new Dictionary<string, string>
{
{ "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<bool> DeleteEcheanceInscritAsync(string idCompte, string nomOpe)
{
var dataBody = new Dictionary<string, string> { { "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<bool> GetStateApi()
{
HttpResponseMessage reponse = await cli.GetAsync(TEST_API_STATEMENT);
if (reponse.IsSuccessStatusCode)
{
return true;
}
else
{
return false;
}
}
}
}

@ -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
{

@ -88,50 +88,46 @@ namespace Data
{
return ClientAPI.DeleteOperationInscritAsync(compte.Identifiant, operation.IntituleOperation).GetAwaiter().GetResult();
}
public IList<Compte> RecupererOperation(Compte compte)
public IList<Operation> 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<Compte> RecupererPlanification(Compte compte)
public IList<Planification> 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<Echeance> RecupererEcheance(Compte compte)
{
throw new NotImplementedException();
}
public IList<Compte> 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();
}
}
}

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

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

@ -35,7 +35,7 @@ namespace Model
public override string ToString()
{
return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit;
return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Tag;
}
}

@ -35,20 +35,19 @@ namespace Model
//actions sur les Opérations
bool AjouterOperation(Compte compte, Operation operation);
bool SupprimerOperation(Compte compte, Operation operation);
IList<Compte> RecupererOperation(Compte compte);
IList<Operation> RecupererOperation(Compte compte);
//actions sur les Planifications
bool AjouterPlanification(Compte compte, Planification planification);
bool SupprimerPlanification(Compte compte, Planification planification);
IList<Compte> RecupererPlanification(Compte compte);
IList<Planification> RecupererPlanification(Compte compte);
//actions sur les Echéances
bool AjouterEcheance(Compte compte);
bool SupprimerEcheance(Compte compte);
bool ModifierEcheance(Compte compte);
IList<Compte> RecupererEcheance(Compte compte);
bool AjouterEcheance(Compte compte, Echeance echeance);
bool SupprimerEcheance(Compte compte, Echeance echeance);
IList<Echeance> RecupererEcheance(Compte compte);
//actions utilitaire

@ -50,7 +50,7 @@ namespace Model
public override string ToString()
{
return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit;
return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + " " + Tag;
}
}
}

@ -8,6 +8,7 @@ namespace Model
{
public enum TagOperation
{
None,
Alimentaire,
Carburant,
Habitation,

@ -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<Inscrit> 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");
@ -212,3 +214,35 @@ foreach (Planification p in planifications)
{
Console.WriteLine(p);
}
Console.WriteLine("\n\n\n----Echeances----\n");
IList<Echeance> 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);
}
Loading…
Cancel
Save