Client API
continuous-integration/drone/push Build is failing Details

pull/138/head
Hugo LIVET 2 years ago
parent 4fcaa57528
commit 995a4b10ee

@ -0,0 +1,93 @@
using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace Data
{
public static class ClientAPI
{
private const string ROOT_URL = "http://82.64.164.20:8888/";
//routes inscrit
private const string GET_INSCRITS_DATA_URL = ROOT_URL+"Inscrit/";
private const string POST_EMAIL_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/FromMail/";
private const string PUT_PASSWORD_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/UpdatePassword/";
private const string POST_ADD_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/add/";
//add all routes
private static HttpClient cli = new HttpClient();
public static async Task<List<Inscrit>> GetInscritsAsync()
{
HttpResponseMessage reponse = await cli.GetAsync(GET_INSCRITS_DATA_URL);
if(reponse.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Inscrit>>(await reponse.Content.ReadAsStringAsync());
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<List<Inscrit>> GetInscritAsync(string email)
{
var dataBody = new Dictionary<string, string> { { "email", email } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_EMAIL_INSCRIT_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Inscrit>>(await reponse.Content.ReadAsStringAsync());
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> PutPasswordInscritAsync(string email, string password)
{
var dataBody = new Dictionary<string, string> { { "email", email }, { "password", password } };
HttpResponseMessage reponse = await cli.PutAsJsonAsync(PUT_PASSWORD_INSCRIT_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return true;
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
public static async Task<bool> PostAddInscritAsync(string nom, string prenom, string email, string password)
{
var dataBody = new Dictionary<string, string> { { "nom", nom }, { "prenom", prenom }, { "email", email }, { "password", password } };
HttpResponseMessage reponse = await cli.PostAsJsonAsync(POST_ADD_INSCRIT_DATA_URL, dataBody);
if (reponse.IsSuccessStatusCode)
{
return true;
}
else
{
throw new HttpRequestException(reponse.StatusCode.ToString());
}
}
}
}

@ -18,6 +18,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Npgsql" Version="6.0.7" /> <PackageReference Include="Npgsql" Version="6.0.7" />
</ItemGroup> </ItemGroup>

@ -296,11 +296,11 @@ namespace LinqToPgSQL
return ListeCompte; return ListeCompte;
} }
public List<Banque> LoadBanqueId(string id) public List<Banque> LoadBanqueId(int id)
{ {
int idnombre = Int16.Parse(id); ;
List<Banque> ListeBanque = new List<Banque>(); List<Banque> ListeBanque = new List<Banque>();
Debug.WriteLine(idnombre); Debug.WriteLine(id);
var conn = new NpgsqlConnection(connexionBDD); var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection"); Console.Out.WriteLine("Ouverture de la connection");
try try
@ -314,7 +314,7 @@ namespace LinqToPgSQL
Environment.Exit(-1); Environment.Exit(-1);
} }
NpgsqlCommand cmd = new NpgsqlCommand("select b.nom,b.urlsite,b.urllogo from banque b, inscrbanque ib, Inscrit i where ib.idinscrit =(@p) AND ib.nombanque = b.nom AND ib.idinscrit = i.id;", conn); NpgsqlCommand cmd = new NpgsqlCommand("select b.nom,b.urlsite,b.urllogo from banque b, inscrbanque ib, Inscrit i where ib.idinscrit =(@p) AND ib.nombanque = b.nom AND ib.idinscrit = i.id;", conn);
cmd.Parameters.AddWithValue("p", idnombre); cmd.Parameters.AddWithValue("p", id);
NpgsqlDataReader dataReader = cmd.ExecuteReader(); NpgsqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read()) while (dataReader.Read())
{ {

@ -9,14 +9,14 @@ namespace Data
public Stub() public Stub()
{ {
lesInscrits.Add(new Inscrit( lesInscrits.Add(new Inscrit(
"1", 1,
"LIVET", "LIVET",
"livet.hugo2003@gmail.com", "livet.hugo2003@gmail.com",
"Hugo", "Hugo",
"Bonjour63." "Bonjour63."
)); ));
} }
public string GetId(string mail) public int GetId(string mail)
{ {
foreach(Inscrit i in lesInscrits) foreach(Inscrit i in lesInscrits)
{ {
@ -25,7 +25,7 @@ namespace Data
return i.Id; return i.Id;
} }
} }
return null; return -1;
} }
public void SupprimerInscritBdd(Inscrit inscrit) public void SupprimerInscritBdd(Inscrit inscrit)
{ {
@ -121,6 +121,16 @@ namespace Data
{ {
return LoadOperation.LoadOperationsFromOFX(ofx); return LoadOperation.LoadOperationsFromOFX(ofx);
} }
string IPersistanceManager.GetId(string mail)
{
throw new NotImplementedException();
}
public List<Banque> LoadBanqueId(int id)
{
throw new NotImplementedException();
}
} }
} }

@ -100,6 +100,10 @@
</MauiImage> </MauiImage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Data\Data.csproj" /> <ProjectReference Include="..\Data\Data.csproj" />
<ProjectReference Include="..\Modele\Model.csproj" /> <ProjectReference Include="..\Modele\Model.csproj" />

@ -18,7 +18,7 @@ namespace Model
void ChangePasswordBdd(string mail, string newMdp); void ChangePasswordBdd(string mail, string newMdp);
string RecupMdpBdd(string mail); string RecupMdpBdd(string mail);
int CalculTotalSoldeComtpe(Inscrit user); int CalculTotalSoldeComtpe(Inscrit user);
List<Banque> LoadBanqueId(string id); List<Banque> LoadBanqueId(int id);
public bool TestConnexionAsDatabase(); public bool TestConnexionAsDatabase();
public List<Banque> ImportBanques(); public List<Banque> ImportBanques();
public Inscrit GetInscrit(string mail); public Inscrit GetInscrit(string mail);

@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
using Model; using Model;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel; using System.ComponentModel;
using Newtonsoft.Json;
namespace Model namespace Model
{ {
@ -15,8 +16,9 @@ namespace Model
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public string Id { get; private set; } public int Id { get; set; }
public string Nom { get; private set; } public string Nom { get; set; }
public string Prenom { get; set; }
public string Mail public string Mail
{ {
@ -36,7 +38,7 @@ namespace Model
} }
private string mail; private string mail;
public string Prenom { get; set; }
public string Mdp public string Mdp
{ {
@ -78,7 +80,9 @@ namespace Model
} }
private List<Banque> lesBanques; private List<Banque> lesBanques;
public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal = 0)
[JsonConstructor]
public Inscrit(int id, string nom, string mail, string prenom, string mdp, double soldeTotal = 0)
{ {
Id = id; Id = id;
Nom = nom; Nom = nom;
@ -87,13 +91,13 @@ namespace Model
Mdp = mdp; Mdp = mdp;
SoldeTotal = soldeTotal; SoldeTotal = soldeTotal;
} }
public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal, List<Banque> lesbanques) public Inscrit(int id, string nom, string mail, string prenom, string mdp, double soldeTotal, List<Banque> lesbanques)
: this(id, nom, mail, prenom, mdp, soldeTotal) : this(id, nom, mail, prenom, mdp, soldeTotal)
{ {
LesBanques = lesbanques; LesBanques = lesbanques;
} }
public Inscrit(string mail, string id) public Inscrit(string mail, int id)
{ {
Prenom = "Lucas"; Prenom = "Lucas";
Mail = mail; Mail = mail;
@ -105,7 +109,6 @@ namespace Model
LesBanques = lesbanques; LesBanques = lesbanques;
} }
public void ajouterBanque(Banque banque) public void ajouterBanque(Banque banque)
{ {
LesBanques.Add(banque); LesBanques.Add(banque);
@ -122,5 +125,9 @@ namespace Model
Dev = devise; Dev = devise;
} }
public override string ToString()
{
return Id + " " + Nom + " " + Prenom + " " + Mail + " " + Mdp;
}
} }
} }

@ -17,4 +17,8 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project> </Project>

@ -1,6 +1,13 @@
using Data; using Data;
using Model; using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
using System.Security.Principal;
using System.Xml.Linq;
//test OFX
/*
Console.WriteLine("Test Deserializer OFX - simplifié"); Console.WriteLine("Test Deserializer OFX - simplifié");
IList<Compte> comptes= new List<Compte>(); IList<Compte> comptes= new List<Compte>();
@ -17,3 +24,39 @@ foreach (Compte compte in comptes)
Console.WriteLine("\t\t"+operation); Console.WriteLine("\t\t"+operation);
} }
} }
*/
//test APIClient
Console.WriteLine("Test ClientAPI");
IList<Inscrit> res = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult();
foreach(Inscrit i in res)
{
Console.WriteLine(i);
}
Console.WriteLine("\n--------\n");
IList<Inscrit> inscrit = ClientAPI.GetInscritAsync("renaudtoutnu@gmail.com").GetAwaiter().GetResult();
foreach (Inscrit i in inscrit)
{
Console.WriteLine(i);
}
Console.WriteLine("\n----Modifs----\n");
bool r = ClientAPI.PutPasswordInscritAsync("lucasevard@gmail.com", "CeciEstUnNouveauMdp123456789!").GetAwaiter().GetResult();
Console.WriteLine("Changement de mdp : "+r+"\n");
bool rr = ClientAPI.PostAddInscritAsync("LIVET", "Hugo", "livet.hugo2003@gmail.com", "EnAvantOuiOui!0").GetAwaiter().GetResult();
Console.WriteLine("Ajout user : " + rr + "\n");
Console.WriteLine("\n----Resultats----\n");
IList<Inscrit> modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult();
foreach (Inscrit i in modif)
{
Console.WriteLine(i);
}

@ -7,6 +7,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Data\Data.csproj" /> <ProjectReference Include="..\Data\Data.csproj" />
<ProjectReference Include="..\Modele\Model.csproj" /> <ProjectReference Include="..\Modele\Model.csproj" />

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Loading…
Cancel
Save