diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index 7c535a4..f1b44d0 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -13,7 +13,7 @@ var builder = WebApplication.CreateBuilder(args); ///NOT WORKING WHEN CHANGING VERSIONS : /// voir sur https://blog.christian-schou.dk/how-to-use-api-versioning-in-net-core-web-api/ rubrique "Configure SwaggerOptions" -/// (mais requiere l'injection de dépendance). +/// (mais requiere l'injection de d�pendance). /// Sinon, code plus simple disponible par le prof @@ -39,6 +39,11 @@ builder.Services.AddControllers(); +//builder.Services.AddScoped(); + + +builder.Services.AddHttpClient(); + //builder.Services.AddScoped(); builder.Services.AddScoped(); 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