From bd8de0eee83e33e3ba3f4d4c036df80b5a7ac1f1 Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Wed, 22 Mar 2023 21:27:08 +0100 Subject: [PATCH] =?UTF-8?q?:zap:=20ajout=20de=20l'httpClientManager=20pour?= =?UTF-8?q?=20la=20liaison=20Client-API=20et=20codage=20des=20fonctions=20?= =?UTF-8?q?principale=20de=20l'httpclient=20(pas=20encore=20test=C3=A9es)?= =?UTF-8?q?=20:package:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/API_LoL/Program.cs | 2 + Sources/HttpClient/HttpClient.csproj | 19 +++ .../HttpClient/HttpClientManager.Champion.cs | 128 ++++++++++++++++++ Sources/HttpClient/HttpClientManager.cs | 29 ++++ Sources/LeagueOfLegends.sln | 6 + 5 files changed, 184 insertions(+) create mode 100644 Sources/HttpClient/HttpClient.csproj create mode 100644 Sources/HttpClient/HttpClientManager.Champion.cs create mode 100644 Sources/HttpClient/HttpClientManager.cs diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index c192eac..a42b38f 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -40,6 +40,8 @@ builder.Services.AddControllers(); builder.Services.AddScoped(); +builder.Services.AddHttpClient(); + var app = builder.Build(); diff --git a/Sources/HttpClient/HttpClient.csproj b/Sources/HttpClient/HttpClient.csproj new file mode 100644 index 0000000..9e4e01f --- /dev/null +++ b/Sources/HttpClient/HttpClient.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Sources/HttpClient/HttpClientManager.Champion.cs b/Sources/HttpClient/HttpClientManager.Champion.cs new file mode 100644 index 0000000..9ffc79b --- /dev/null +++ b/Sources/HttpClient/HttpClientManager.Champion.cs @@ -0,0 +1,128 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Json; +using System.Reflection; +using System.Reflection.Metadata; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace HttpClient +{ + public partial class HttpClientManager + { + public class ChampionManager : IChampionsManager + { + + + private readonly HttpClientManager parent; + + private System.Net.Http.HttpClient httpc; + + public string BaseAddress; + + + public ChampionManager(HttpClientManager parent, System.Net.Http.HttpClient httpc) { + + this.httpc = httpc; + this.parent = parent; + } + + public async Task AddItem(Champion? item) //return le champion ajouté, null sinon ? + { + if(item==null) throw new ArgumentNullException("item is null"); + var response = await httpc.PostAsJsonAsync("/Champion?Name = " + item.Name, item); + + return response.IsSuccessStatusCode ? item : null; + } + + public async Task DeleteItem(Champion? item) + { + HttpResponseMessage response = await httpc.DeleteAsync("/Champion?Name=" + item.Name); + return response.IsSuccessStatusCode; + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return httpc.GetFromJsonAsync>("/Champion?index="+index+"&size="+count); + } + + + + + + public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return httpc.GetFromJsonAsync>("/Champion?name="+substring+"&index=" + index + "&size=" + count); + } + + public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByCharacteristic(string charName) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByClass(ChampionClass championClass) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByName(string substring) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByRunePage(RunePage? runePage) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsBySkill(Skill? skill) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsBySkill(string skill) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Champion? oldItem, Champion? newItem) + { + throw new NotImplementedException(); + } + } + } +} diff --git a/Sources/HttpClient/HttpClientManager.cs b/Sources/HttpClient/HttpClientManager.cs new file mode 100644 index 0000000..49ddb70 --- /dev/null +++ b/Sources/HttpClient/HttpClientManager.cs @@ -0,0 +1,29 @@ +using Model; + +namespace HttpClient +{ + public partial class HttpClientManager : IDataManager + { + + + public System.Net.Http.HttpClient httpC { get; set; } = new System.Net.Http.HttpClient(); + + public string BaseAddress; + + + public HttpClientManager() { + ChampionsMgr = new ChampionManager(this, httpC); + httpC.BaseAddress = new Uri("https://localhost:7144/api/"); + + } + + public ISkinsManager SkinsMgr => throw new NotImplementedException(); + + public IRunesManager RunesMgr => throw new NotImplementedException(); + + public IRunePagesManager RunePagesMgr => throw new NotImplementedException(); + + public IChampionsManager ChampionsMgr { get; set; } + + } +} diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index a5d27bb..007e972 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient", "HttpClient\HttpClient.csproj", "{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -64,6 +66,10 @@ Global {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.Build.0 = Debug|Any CPU {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.ActiveCfg = Release|Any CPU {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.Build.0 = Release|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.36.3