Ajout routes Opération
continuous-integration/drone/push Build is failing Details

pull/138/head
Hugo LIVET 2 years ago
parent 4e150819bc
commit 0f3872e8f2

@ -17,6 +17,7 @@ $app->get('/', function (Request $request, Response $response, $args) {
require __DIR__.'/../routes/Inscrit.php'; require __DIR__.'/../routes/Inscrit.php';
require __DIR__.'/../routes/Banque.php'; require __DIR__.'/../routes/Banque.php';
require __DIR__.'/../routes/Compte.php'; require __DIR__.'/../routes/Compte.php';
require __DIR__.'/../routes/Operation.php';
$app->run(); $app->run();
?> ?>

@ -0,0 +1,123 @@
<?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/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);
}
});
?>

@ -35,6 +35,10 @@ namespace Data
private const string POST_ADD_COMPTE_INSCRIT_DATA_URL = ROOT_URL + "Compte/add/"; 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 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 //add all routes
@ -253,5 +257,70 @@ namespace Data
} }
//Operations
public static async Task<List<Operation>> GetOperationAsync(string id)
{
var dataBody = new Dictionary<string, string> { { "id", id } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_OPERATION_COMPTE_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Operation>>(await reponse.Content.ReadAsStringAsync());
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> PostAddOperationInscritAsync(Compte compte, Operation operation)
{
var dataBody = new Dictionary<string, string>
{
{ "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<bool> DeleteOperationInscritAsync(string nomCompte, string nomOpe)
{
var dataBody = new Dictionary<string, string> { { "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());
}
}
} }
} }

@ -67,28 +67,24 @@ namespace Data
//actions sur les comptes //actions sur les comptes
public bool AjouterCompte(Compte compte, Inscrit inscrit) 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) public bool SupprimerCompte(Compte compte, Inscrit inscrit)
{ {
throw new NotImplementedException(); return ClientAPI.DeleteCompteInscritAsync(compte.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult();
} }
public IList<Compte> RecupererCompte(Banque banque, Inscrit inscrit) public IList<Compte> RecupererCompte(Banque banque, Inscrit inscrit)
{ {
throw new NotImplementedException(); return ClientAPI.GetCompteAsync(inscrit.Id.ToString()).GetAwaiter().GetResult();
} }
//actions sur les Opérations //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(); throw new NotImplementedException();
} }
public bool ModifierOperation(Compte compte) public bool SupprimerOperation(Compte compte, Operation operation)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

@ -126,15 +126,11 @@ namespace Data
//actions sur les Opérations //actions sur les Opérations
public bool AjouterOperation(Compte compte) public bool AjouterOperation(Compte compte, Operation operation)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool SupprimerOperation(Compte compte) public bool SupprimerOperation(Compte compte, Operation operation)
{
throw new NotImplementedException();
}
public bool ModifierOperation(Compte compte)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

@ -7,11 +7,11 @@ INSERT INTO Devise VALUES('NZD','DOLLAR NEO-ZELANDAIS');
INSERT INTO Devise VALUES('ZAR','RANd'); 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('EVARD','LUCAS','lucasevard@gmail.com','Azerty12345678!');
INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES('MONCUL','STEPHANE','stef@gmail.com','teststef'); 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','test000'); 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','BENJAMIN'); 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','zizi'); INSERT INTO Inscrit (nom,prenom,mail,mdp)VALUES('TUBEAU','RAOUL','raoullacouille@gmail.com','Azerty12345678!');
INSERT INTO DeviseInscrit VALUES('EUR','1'); INSERT INTO DeviseInscrit VALUES('EUR','1');
INSERT INTO DeviseInscrit VALUES('JPY','2'); 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','2');
INSERT INTO Compte (nom,idInscritBanque)VALUES('LIVRET A','3'); INSERT INTO Compte (nom,idInscritBanque)VALUES('LIVRET A','3');
INSERT INTO Compte (nom,idInscritBanque)VALUES('LIVRET A','4'); 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');

@ -62,44 +62,38 @@ CREATE TABLE Compte
CREATE TABLE Echeancier CREATE TABLE Echeancier
( (
id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, id MEDIUMINT PRIMARY KEY AUTO_INCREMENT,
nom varchar(40),
credit numeric,
compte MEDIUMINT, compte MEDIUMINT,
debit numeric, nom varchar(40),
dateE date, montant numeric,
datecrea date, dateO date,
methodePayement varchar(20), methodePayement varchar(20),
CONSTRAINT ck_echan CHECK (methodePayement IN ('CB','Cheque','Espece','Prélevement')), isDebit boolean,
FOREIGN KEY(compte) REFERENCES Compte(id), CONSTRAINT ck_ech CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')),
UNIQUE (datecrea,compte) FOREIGN KEY(compte) REFERENCES Compte(id)
); );
CREATE TABLE Operation CREATE TABLE Operation
( (
id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, id MEDIUMINT PRIMARY KEY AUTO_INCREMENT,
nom varchar(40),
credit numeric,
compte MEDIUMINT, compte MEDIUMINT,
debit numeric, nom varchar(40),
montant numeric,
dateO date, dateO date,
datecrea date,
methodePayement varchar(20), methodePayement varchar(20),
CONSTRAINT ck_methPaye CHECK (methodePayement IN ('CB','Cheque','Espece','Prélevement')), isDebit boolean,
FOREIGN KEY(compte) REFERENCES Compte(id), CONSTRAINT ck_methPaye CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')),
UNIQUE (datecrea,compte) FOREIGN KEY(compte) REFERENCES Compte(id)
); );
CREATE TABLE Planification CREATE TABLE Planification
( (
id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, id MEDIUMINT PRIMARY KEY AUTO_INCREMENT,
nom varchar(40),
credit numeric,
compte MEDIUMINT, compte MEDIUMINT,
debit numeric, nom varchar(40),
dateP date, montant numeric,
datecrea date, dateO date,
methodePayement varchar(20), methodePayement varchar(20),
CONSTRAINT ck_planif CHECK (methodePayement IN ('CB','Cheque','Espece','Prélevement')), isDebit boolean,
FOREIGN KEY(compte) REFERENCES Compte(id), CONSTRAINT ck_pla CHECK (methodePayement IN ('Cb','Esp','Chq','Vir','Pre')),
UNIQUE (datecrea,compte) FOREIGN KEY(compte) REFERENCES Compte(id)
); );

@ -33,9 +33,8 @@ namespace Model
//actions sur les Opérations //actions sur les Opérations
bool AjouterOperation(Compte compte); bool AjouterOperation(Compte compte, Operation operation);
bool SupprimerOperation(Compte compte); bool SupprimerOperation(Compte compte, Operation operation);
bool ModifierOperation(Compte compte);
IList<Compte> RecupererOperation(Compte compte); IList<Compte> RecupererOperation(Compte compte);

@ -97,13 +97,6 @@ namespace Model
LesBanques = lesbanques; LesBanques = lesbanques;
} }
public Inscrit(string mail, int id)
{
Prenom = "Lucas";
Mail = mail;
Id = id;
}
public Inscrit(List<Banque> lesbanques) public Inscrit(List<Banque> lesbanques)
{ {
LesBanques = lesbanques; LesBanques = lesbanques;

@ -12,6 +12,7 @@ namespace Model
Cb, Cb,
Esp, Esp,
Chq, Chq,
Vir Vir,
Pre
} }
} }

@ -1,4 +1,5 @@
using System; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
@ -32,6 +33,7 @@ namespace Model
public bool IsDebit { get; private set; } public bool IsDebit { 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, bool isDebit=true)
{ {
IntituleOperation = intituleOperation; IntituleOperation = intituleOperation;
@ -45,7 +47,7 @@ namespace Model
public override string ToString() public override string ToString()
{ {
return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit + "\n"; return IntituleOperation + " " + DateOperation + " " + Montant + " " + ModePayement + " " + IsDebit;
} }
} }
} }

@ -148,3 +148,35 @@ foreach (Compte c in comptes)
{ {
Console.WriteLine(c); Console.WriteLine(c);
} }
Console.WriteLine("\n\n\n----Operations----\n");
IList<Operation> 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);
}
Loading…
Cancel
Save