Ajout des routes des banques
continuous-integration/drone/push Build is failing Details

pull/138/head
Hugo LIVET 2 years ago
parent add061d7b4
commit 74d30d2522

@ -74,9 +74,9 @@ $app->post('/Banque/FromId/', function(Request $request, Response $response,arra
$app->post('/Banque/add/', function(Request $request, Response $response, array $args){ $app->post('/Banque/add/', function(Request $request, Response $response, array $args){
$nom = $request->getParsedBody()["nom"]; $nom = $request->getParsedBody()["nom"];
$idInscrit = $request->getParsedBody()["idIscrit"]; $idInscrit = $request->getParsedBody()["idInscrit"];
$query = "INSERT INTO InscrBanque (nomBanque, idInscrit) VALUES (:nom, :idInscrit) WHERE EXISTS (SELECT nom FROM Banque WHERE nom=:nom)"; $query = "INSERT INTO InscrBanque (nomBanque, idInscrit) VALUES (:nom, :idI)";
try{ try{
$db = new Database(); $db = new Database();
@ -84,7 +84,7 @@ $app->post('/Banque/add/', function(Request $request, Response $response, array
$stmt = $conn->prepare($query); $stmt = $conn->prepare($query);
$stmt->bindValue(':nom', $nom, PDO::PARAM_STR); $stmt->bindValue(':nom', $nom, PDO::PARAM_STR);
$stmt->bindValue(':idInscrit', $idInscrit, PDO::PARAM_STR); $stmt->bindValue(':idI', $idInscrit, PDO::PARAM_STR);
$result = $stmt->execute(); $result = $stmt->execute();
@ -105,9 +105,9 @@ $app->post('/Banque/add/', function(Request $request, Response $response, array
$app->delete('/Banque/delete/', function (Request $request, Response $response, array $args) { $app->delete('/Banque/delete/', function (Request $request, Response $response, array $args) {
$nom = $request->getParsedBody()["nom"]; $nom = $request->getParsedBody()["nom"];
$idInscrit = $request->getParsedBody()["idIscrit"]; $idInscrit = $request->getParsedBody()["idInscrit"];
$query = "DELETE FROM InscrBanque WHERE nom=:nom AND idInscrit=:idI"; $query = "DELETE FROM InscrBanque WHERE nomBanque=:nom AND idInscrit=:idI";
try{ try{
$db = new Database(); $db = new Database();

@ -137,6 +137,60 @@ namespace Data
} }
} }
public static async Task<List<Banque>> GetBanqueAsync(string id)
{
var dataBody = new Dictionary<string, string> { { "id", id } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_BANQUES_INSCRIT_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Banque>>(await reponse.Content.ReadAsStringAsync());
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> PostAddBanqueInscritAsync(string nomBanque, string idInscrit)
{
var dataBody = new Dictionary<string, string> { { "nom", nomBanque }, { "idInscrit", idInscrit } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_BANQUE_INSCRIT_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return true;
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> DeleteBanqueInscritAsync(string nomBanque, string idInscrit)
{
var dataBody = new Dictionary<string, string> { { "nom", nomBanque }, { "idInscrit", idInscrit } };
var reponse =
cli.SendAsync(
new HttpRequestMessage(HttpMethod.Delete, DELETE_BANQUE_INSCRIT_DATA_URL)
{
Content = new FormUrlEncodedContent(dataBody)
})
.Result;
if (reponse.IsSuccessStatusCode)
{
return true;
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
} }

@ -48,19 +48,19 @@ namespace Data
//actions sur les banques //actions sur les banques
public bool AjouterBanque(Banque banque, Inscrit inscrit) public bool AjouterBanque(Banque banque, Inscrit inscrit)
{ {
throw new NotImplementedException(); return ClientAPI.PostAddBanqueInscritAsync(banque.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult();
} }
public bool SupprimerBanque(Banque banque, Inscrit inscrit) public bool SupprimerBanque(Banque banque, Inscrit inscrit)
{ {
throw new NotImplementedException(); return ClientAPI.DeleteBanqueInscritAsync(banque.Nom, inscrit.Id.ToString()).GetAwaiter().GetResult();
} }
public IList<Banque> RecupererBanques(Inscrit inscrit) public IList<Banque> RecupererBanques(Inscrit inscrit)
{ {
throw new NotImplementedException(); return ClientAPI.GetBanqueAsync(inscrit.Id.ToString()).GetAwaiter().GetResult();
} }
public IList<Banque> RecupererBanquesDisponible() public IList<Banque> RecupererBanquesDisponible()
{ {
throw new NotImplementedException(); return ClientAPI.GetBanquesAsync().GetAwaiter().GetResult();
} }

@ -31,6 +31,8 @@ foreach (Compte compte in comptes)
Console.WriteLine("Test ClientAPI"); Console.WriteLine("Test ClientAPI");
Console.WriteLine("\n\n\n----Inscrits----\n");
IList<Inscrit> res = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); IList<Inscrit> res = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult();
foreach(Inscrit i in res) foreach(Inscrit i in res)
{ {
@ -64,7 +66,7 @@ foreach (Inscrit i in modif)
Console.WriteLine("\n----Modifs----\n"); Console.WriteLine("\n----Modifs----\n");
bool rrr = ClientAPI.DeleteInscritAsync("livet.hugo2003@gmail.com").GetAwaiter().GetResult(); bool rrr = ClientAPI.DeleteInscritAsync("livet.hugo2003@gmail.com").GetAwaiter().GetResult();
Console.WriteLine("Del user : " + rr + "\n"); Console.WriteLine("Del user : " + rrr + "\n");
modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult();
@ -80,3 +82,37 @@ foreach (Banque b in banques)
{ {
Console.WriteLine(b); Console.WriteLine(b);
} }
Console.WriteLine("\n--------\n");
IList<Banque> banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult();
foreach (Banque b in banquesId1)
{
Console.WriteLine(b);
}
Console.WriteLine("\n----Modifs----\n");
bool rrrr = ClientAPI.PostAddBanqueInscritAsync("ORANGE BANK","1").GetAwaiter().GetResult();
Console.WriteLine("Add banque for user : " + rrrr + "\n");
Console.WriteLine("\n----Verif----\n");
banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult();
foreach (Banque b in banquesId1)
{
Console.WriteLine(b);
}
Console.WriteLine("\n----Modifs----\n");
bool rrrrrr = ClientAPI.DeleteBanqueInscritAsync("ORANGE BANK", "1").GetAwaiter().GetResult();
Console.WriteLine("Del banque for user : " + rrrrrr + "\n");
Console.WriteLine("\n----Verif----\n");
banquesId1 = ClientAPI.GetBanqueAsync("1").GetAwaiter().GetResult();
foreach (Banque b in banquesId1)
{
Console.WriteLine(b);
}
Loading…
Cancel
Save