From 4e40a8a4aa23ab36e91d97f214d5ff6af0200964 Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Fri, 3 Mar 2023 15:06:55 +0100 Subject: [PATCH 1/9] :green_heart: add deploy container to .drone.yml --- .drone.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.drone.yml b/.drone.yml index e694160..8533d56 100644 --- a/.drone.yml +++ b/.drone.yml @@ -61,4 +61,15 @@ steps: sonar_token: from_secret: SECRET_SONAR_LOGIN depends_on: [docker-build-and-push] + + # container deployment + - name: deploy-container + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: hub.codefirst.iut.uca.fr/corentin.richard/entityframework_consodeservices_tp:latest + CONTAINERNAME: entityframework_consodeservices_tp + COMMAND: create + OVERWRITE: true + ADMIN: corentinrichard,pierreferreira + depends_on: [ code-analysis, docker-build-and-push ] From 3e960f4b8cedac11c294a1edbe7f30b06eebbcf7 Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Tue, 7 Mar 2023 18:21:09 +0100 Subject: [PATCH 2/9] Remove useless project --- Sources/LeagueOfLegends.sln | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 6415543..5049af2 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C76D0C23-1FFA-4963-93CD-E12BD643F030}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTests", "Tests\ConsoleTests\ConsoleTests.csproj", "{1889FA6E-B7C6-416E-8628-9449FB9070B9}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{3B720C0C-53FE-4642-A2DB-87FD8634CD74}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B163-4731-A4D1-AFE8A7C4C170}" @@ -23,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework", "EntityFr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csproj", "{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -35,10 +33,6 @@ Global {2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU {2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU {2960F9BA-49DE-494D-92E3-CE5A794BA1A9}.Release|Any CPU.Build.0 = Release|Any CPU - {1889FA6E-B7C6-416E-8628-9449FB9070B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1889FA6E-B7C6-416E-8628-9449FB9070B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1889FA6E-B7C6-416E-8628-9449FB9070B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1889FA6E-B7C6-416E-8628-9449FB9070B9}.Release|Any CPU.Build.0 = Release|Any CPU {3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Debug|Any CPU.Build.0 = Debug|Any CPU {3B720C0C-53FE-4642-A2DB-87FD8634CD74}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -72,7 +66,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} {20A1A7DC-1E93-4506-BD32-8597A5DADD7B} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {74F469C3-A94A-4507-9DC7-7DBADCD18173} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} From e6b686772ff9a5fcdeeaa225ff03c4e19a04de9f Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:25:32 +0100 Subject: [PATCH 3/9] Adding getChampionByName and Get skills by champion name --- .../Controllers/ChampionsController.cs | 50 +++++++++++++++---- Sources/API_LoL/Mapper/SkinMapper.cs | 18 +++++++ Sources/DTO/SkinDTO.cs | 23 +++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 Sources/API_LoL/Mapper/SkinMapper.cs create mode 100644 Sources/DTO/SkinDTO.cs diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 9aefc31..7752f0c 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -4,6 +4,9 @@ using StubLib; using DTO; using DTO.Mapper; using System.CodeDom.Compiler; +using System.Drawing; +using System; +using API_LoL.Mapper; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -15,29 +18,23 @@ namespace API_LoL.Controllers { public ChampionsController(IDataManager Manager) { - this.ChampionsManager= Manager.ChampionsMgr; + this.ChampionsManager = Manager.ChampionsMgr; + this.SkinsManager = Manager.SkinsMgr; } private IChampionsManager ChampionsManager; + private ISkinsManager SkinsManager; // GET api//5 [HttpGet] - public async Task Get(String? name= null,String? skill = null, String? characteristic = null,int index = 0,int size =10) + public async Task Get(String? skill = null, String? characteristic = null,int index = 0,int size =10) { if (size - index > 10) { return BadRequest(); } - if (!string.IsNullOrEmpty(name)) - { - var list = await ChampionsManager.GetItemsByName(name, index,size); - if (list.Count() != 0) - { - return Ok(list.Select(champion => champion?.ToDTO())); - } - else { return NoContent(); } - }else if(!string.IsNullOrEmpty(skill)) { + if(!string.IsNullOrEmpty(skill)) { var list = await ChampionsManager.GetItemsBySkill(skill, index, size); if (list.Count() != 0) { @@ -63,6 +60,37 @@ namespace API_LoL.Controllers } } + [HttpGet("name")] + public async Task GetByName(String name) + { + if (string.IsNullOrEmpty(name)) return BadRequest(); + var list = await ChampionsManager.GetItemsByName(name, 0, 1); + if (list.Count() == 1) + { + return Ok(list.Select(champion => champion?.ToDTO()).First()); + } + else { return NoContent(); } + + } + + [HttpGet("name/skills")] + public async Task GetSkillsByName(String name) + { + if (string.IsNullOrEmpty(name)) return BadRequest(); + var list = await ChampionsManager.GetItemsByName(name, 0, 1); + if (list.Count() == 1) + { + var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); + if(skins.Count() != 0) + { + return Ok(skins.Select(skin => skin?.ToDTO())); + } + else { return NoContent(); } + } + else { return NoContent(); } + + } + // POST api/ [HttpPost] public async Task Post(ChampionDTO champion) diff --git a/Sources/API_LoL/Mapper/SkinMapper.cs b/Sources/API_LoL/Mapper/SkinMapper.cs new file mode 100644 index 0000000..25ac8f6 --- /dev/null +++ b/Sources/API_LoL/Mapper/SkinMapper.cs @@ -0,0 +1,18 @@ +using DTO; +using Model; + +namespace API_LoL.Mapper +{ + public static class SkinMapper + { + public static SkinDTO ToDTO(this Skin skin) + { + return new SkinDTO(skin.Name, skin.Description, skin.Icon); + } + + public static Skin ToSkin(this SkinDTO skin) + { + return new Skin(skin.Name, null, icon:skin.Icon) ; + } + } +} diff --git a/Sources/DTO/SkinDTO.cs b/Sources/DTO/SkinDTO.cs new file mode 100644 index 0000000..32696d6 --- /dev/null +++ b/Sources/DTO/SkinDTO.cs @@ -0,0 +1,23 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkinDTO + { + public string Name { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + + public SkinDTO(string name,string description,string icon) { + this.Name = name; + this.Description = description; + this.Icon = icon; + + } + } +} From f7a6e775545c9f00c42c6e5edd361a399e3666f4 Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Tue, 7 Mar 2023 19:26:03 +0100 Subject: [PATCH 4/9] =?UTF-8?q?:bookmark:=20D=C3=A9but=20du=20versionning,?= =?UTF-8?q?=20probl=C3=A8me=20au=20niveau=20de=20swagger,=20voir=20le=20co?= =?UTF-8?q?de=20du=20prof=20ou=20tenter=20un=20SwaggerOption,=20qui=20rest?= =?UTF-8?q?e=20compliquer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/API_LoL/API_LoL.csproj | 2 + .../Controllers/ChampionsController.cs | 4 +- .../ChampionsControllerVersioned.cs | 106 ++++++++++++++++++ Sources/API_LoL/Program.cs | 41 ++++++- 4 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs diff --git a/Sources/API_LoL/API_LoL.csproj b/Sources/API_LoL/API_LoL.csproj index 5ada54d..a8c4de7 100644 --- a/Sources/API_LoL/API_LoL.csproj +++ b/Sources/API_LoL/API_LoL.csproj @@ -9,6 +9,8 @@ + + diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 9aefc31..acad597 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -9,7 +9,9 @@ using System.CodeDom.Compiler; namespace API_LoL.Controllers { - [Route("api/[controller]")] + //[Route("api/[controller]")] + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]")] [ApiController] public class ChampionsController : ControllerBase { diff --git a/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs b/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs new file mode 100644 index 0000000..e8b3a24 --- /dev/null +++ b/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs @@ -0,0 +1,106 @@ +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; +using DTO; +using DTO.Mapper; +using System.CodeDom.Compiler; + +namespace API_LoL.Controllers +{ + [ApiVersion("2.0")] + [ApiVersion("2.2")] + [Route("api/v{version:apiVersion}/versioned")] + [ApiController] + public class ChampionsControllerVersioned : ControllerBase + { + public ChampionsControllerVersioned(IDataManager Manager) + { + this.ChampionsManager = Manager.ChampionsMgr; + } + + private IChampionsManager ChampionsManager; + + // GET api//5 + + [HttpGet] + public async Task Get(String? name = null, String? skill = null, String? characteristic = null, int index = 0, int size = 10) + { + if (size - index > 10) + { + return BadRequest(); + } + if (!string.IsNullOrEmpty(name)) + { + var list = await ChampionsManager.GetItemsByName(name, index, size); + if (list.Count() != 0) + { + return Ok(list.Select(champion => champion?.ToDTO())); + } + else { return NoContent(); } + } + else if (!string.IsNullOrEmpty(skill)) + { + var list = await ChampionsManager.GetItemsBySkill(skill, index, size); + if (list.Count() != 0) + { + return Ok(list.Select(champion => champion?.ToDTO())); + } + else { return NoContent(); } + } + else if (!string.IsNullOrEmpty(characteristic)) + { + var list = await ChampionsManager.GetItems(index, size); + if (list.Count() != 0) + { + return Ok(list.Select(champion => champion?.ToDTO())); + } + else { return NoContent(); } + } + else + { + var list = await ChampionsManager.GetItems(index, size); + if (list.Count() != 0) + { + return Ok(list.Select(champion => champion?.ToDTO())); + } + else { return NoContent(); } + } + } + + + // POST api/ + [HttpPost] + public async Task Post(ChampionDTO champion) + { + if (champion == null) + { + return UnprocessableEntity(); + } + else + { + await ChampionsManager.AddItem(champion.ToChampion()); + return CreatedAtAction("Post", champion); + } + } + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + + + ///---------- Versioning ----------/// + [HttpGet] + public string GetThatOnlySayHello() => "Hello v2.0!"; + + [HttpGet, MapToApiVersion("2.2")] + public string GetThatOnlySayHelloV2() => "Hello but i'm from v2.2!"; + } +} diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index d4fb3b8..b8f9f47 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -1,24 +1,59 @@ +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc.Versioning; using Model; using StubLib; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. -builder.Services.AddControllers(); +//Versioning + +///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). +/// Sinon, code plus simple disponible par le prof + + + +// Add ApiExplorer to discover versions +builder.Services.AddVersionedApiExplorer(setup => +{ + setup.GroupNameFormat = "'v'VVV"; + setup.SubstituteApiVersionInUrl = true; +}); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); + +builder.Services.AddApiVersioning(o => o.ApiVersionReader = new UrlSegmentApiVersionReader()); + +// Add services to the container. +builder.Services.AddControllers(); + + + builder.Services.AddScoped(); var app = builder.Build(); +var apiVersionDescriptionProvider = app.Services.GetRequiredService(); + + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwaggerUI(options => + { + + foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions) + { + options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", + description.GroupName.ToUpperInvariant()); + } + }); } app.UseHttpsRedirection(); From f4b77f66e7cdbd1effd254f9cd503a8743c09c66 Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:07:52 +0100 Subject: [PATCH 5/9] Adding ChampionClass to ChampionDTO --- .../Controllers/ChampionsController.cs | 27 +++++++++++---- Sources/API_LoL/Mapper/ChampionClassMapper.cs | 34 +++++++++++++++++++ Sources/API_LoL/Mapper/ChampionMapper.cs | 7 ++-- Sources/DTO/ChampionClassDTO.cs | 16 +++++++++ Sources/DTO/ChampionDTO.cs | 15 +++----- 5 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 Sources/API_LoL/Mapper/ChampionClassMapper.cs create mode 100644 Sources/DTO/ChampionClassDTO.cs diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 7752f0c..8ef8ca7 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -73,26 +73,41 @@ namespace API_LoL.Controllers } - [HttpGet("name/skills")] - public async Task GetSkillsByName(String name) + [HttpGet("name/skins")] + public async Task GetSkinsByName(String name) { if (string.IsNullOrEmpty(name)) return BadRequest(); var list = await ChampionsManager.GetItemsByName(name, 0, 1); if (list.Count() == 1) { var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); - if(skins.Count() != 0) + if (skins.Count() != 0) { return Ok(skins.Select(skin => skin?.ToDTO())); } else { return NoContent(); } } else { return NoContent(); } - } - // POST api/ - [HttpPost] + [HttpGet("name/largeImage")] + public async Task GetLargeImageByName(String name) + { + if (string.IsNullOrEmpty(name)) return BadRequest(); + var list = await ChampionsManager.GetItemsByName(name, 0, 1); + if (list.Count() == 1) + { + var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); + if (skins.Count() != 0) + { + return Ok(skins.Select(skin => skin?.ToDTO())); + } + else { return NoContent(); } + } + else { return NoContent(); } + + // POST api/ + [HttpPost] public async Task Post(ChampionDTO champion) { if (champion == null) diff --git a/Sources/API_LoL/Mapper/ChampionClassMapper.cs b/Sources/API_LoL/Mapper/ChampionClassMapper.cs new file mode 100644 index 0000000..638f500 --- /dev/null +++ b/Sources/API_LoL/Mapper/ChampionClassMapper.cs @@ -0,0 +1,34 @@ +using DTO; +using Model; + +namespace API_LoL.Mapper +{ + public static class ChampionClassMapper + { + public static string ToDTO(this ChampionClass championClass) + { + return championClass.ToString(); + } + + public static ChampionClass ToChampionClass(this String championClass) + { + switch (championClass) + { + case "Assassin": + return ChampionClass.Assassin; + case "Fighter": + return ChampionClass.Fighter; + case "Mage": + return ChampionClass.Mage; + case "Marksman": + return ChampionClass.Marksman; + case "Support": + return ChampionClass.Support; + case "Tank": + return ChampionClass.Tank; + default: + return ChampionClass.Unknown; + } + } + } +} diff --git a/Sources/API_LoL/Mapper/ChampionMapper.cs b/Sources/API_LoL/Mapper/ChampionMapper.cs index c2e8d0b..3dd6a11 100644 --- a/Sources/API_LoL/Mapper/ChampionMapper.cs +++ b/Sources/API_LoL/Mapper/ChampionMapper.cs @@ -1,4 +1,5 @@ -using Model; +using API_LoL.Mapper; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -11,13 +12,13 @@ namespace DTO.Mapper { public static ChampionDTO ToDTO(this Champion champion) { - return new ChampionDTO(champion.Name, champion.Bio, champion.Icon); + return new ChampionDTO(champion.Name, champion.Bio, champion.Icon,champion.Class.ToDTO().ToString()); //return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills); } public static Champion ToChampion(this ChampionDTO champion) { - Champion champ = new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio); + Champion champ = new Champion(champion.Name, champion.Class.ToChampionClass(), champion.Icon, "", champion.Bio); //foreach (Skill skill in champion.Skills) //{ diff --git a/Sources/DTO/ChampionClassDTO.cs b/Sources/DTO/ChampionClassDTO.cs new file mode 100644 index 0000000..c85525f --- /dev/null +++ b/Sources/DTO/ChampionClassDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class ChampionClassDTO + { + public string Name; + public ChampionClassDTO(string name) { + this.Name = name; + } + } +} diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs index 922d56e..723d7b4 100644 --- a/Sources/DTO/ChampionDTO.cs +++ b/Sources/DTO/ChampionDTO.cs @@ -5,26 +5,19 @@ namespace DTO { public class ChampionDTO { - public ChampionDTO(string name, string bio, string icon) + public ChampionDTO(string name, string bio, string icon, string championClassDTO) { Name = name; Bio = bio; Icon = icon; + Class = championClassDTO; } - - //public ChampionDTO(string name, string bio, string icon, ICollection skills) - //{ - // Name = name; - // Bio = bio; - // Icon = icon; - // Skills = skills; - //} - public string Name { get; set; } public string Bio { get; set; } - //public ChampionClass Class { get; set; } public string Icon { get; set; } + public string Class { get; set; } + public bool equals(ChampionDTO other) { return other.Name==this.Name && other.Bio==this.Bio && other.Icon==this.Icon; From dc64edf23a5c4c77fce476070f9be3af6906a114 Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:19:27 +0100 Subject: [PATCH 6/9] bug solving :bug: --- .../Controllers/ChampionsController.cs | 30 ++++++-------- Sources/Api_UT/ChampionControllerTest.cs | 10 ++--- Sources/Api_UT/UnitTest1.cs | 41 ------------------- 3 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 Sources/Api_UT/UnitTest1.cs diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 8ef8ca7..ce8b87e 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -7,6 +7,7 @@ using System.CodeDom.Compiler; using System.Drawing; using System; using API_LoL.Mapper; +using System.Xml.Linq; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -28,13 +29,22 @@ namespace API_LoL.Controllers // GET api//5 [HttpGet] - public async Task Get(String? skill = null, String? characteristic = null,int index = 0,int size =10) + public async Task Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10) { if (size - index > 10) { return BadRequest(); } - if(!string.IsNullOrEmpty(skill)) { + if (!string.IsNullOrEmpty(name)) + { + var list = await ChampionsManager.GetItemsByName(name, index, size); + if (list.Count() != 0) + { + return Ok(list.Select(champion => champion?.ToDTO())); + } + else { return NoContent(); } + } + else if(!string.IsNullOrEmpty(skill)) { var list = await ChampionsManager.GetItemsBySkill(skill, index, size); if (list.Count() != 0) { @@ -90,22 +100,6 @@ namespace API_LoL.Controllers else { return NoContent(); } } - [HttpGet("name/largeImage")] - public async Task GetLargeImageByName(String name) - { - if (string.IsNullOrEmpty(name)) return BadRequest(); - var list = await ChampionsManager.GetItemsByName(name, 0, 1); - if (list.Count() == 1) - { - var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); - if (skins.Count() != 0) - { - return Ok(skins.Select(skin => skin?.ToDTO())); - } - else { return NoContent(); } - } - else { return NoContent(); } - // POST api/ [HttpPost] public async Task Post(ChampionDTO champion) diff --git a/Sources/Api_UT/ChampionControllerTest.cs b/Sources/Api_UT/ChampionControllerTest.cs index 16fccaa..a3ca675 100644 --- a/Sources/Api_UT/ChampionControllerTest.cs +++ b/Sources/Api_UT/ChampionControllerTest.cs @@ -21,7 +21,7 @@ namespace Api_UT public async Task Get_Default_OkList() { - List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") }; + List list = new List {new ChampionDTO("Akali","","","Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter"), new ChampionDTO("Ahri", "", "", "Mage"), new ChampionDTO("Akshan", "", "", "Marksman"), new ChampionDTO("Bard", "", "","Support"), new ChampionDTO("Alistar", "", "","Tank") }; IActionResult a = await api.Get(); a.Should().NotBeNull(); var aObject = a as OkObjectResult; @@ -42,7 +42,7 @@ namespace Api_UT [TestMethod] public async Task Get_2First_OkListOf2() { - List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") }; + List list = new List { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") }; IActionResult a = await api.Get(index: 0,size: 2); @@ -57,7 +57,7 @@ namespace Api_UT [TestMethod] public async Task Get_FilterAName_OkListOf5() { - List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") }; + List list = new List { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") }; IActionResult a = await api.Get(name: "Ak"); @@ -75,9 +75,9 @@ namespace Api_UT public async Task Post_ValidChampion_Created() { ChampionsController api = new ChampionsController(new StubData()); - IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon")); + IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin")); Assert.IsNotNull(a); - ChampionDTO champ = new ChampionDTO("nom", "bio", "icon"); + ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin"); Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value)); } diff --git a/Sources/Api_UT/UnitTest1.cs b/Sources/Api_UT/UnitTest1.cs deleted file mode 100644 index de78d2b..0000000 --- a/Sources/Api_UT/UnitTest1.cs +++ /dev/null @@ -1,41 +0,0 @@ -using API_LoL.Controllers; -using DTO; -using FluentAssertions; -using Microsoft.AspNetCore.Mvc; -using Model; -using StubLib; - -namespace Api_UT -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public async Task TestGet() - { - List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") }; - ChampionsController api = new ChampionsController(new StubData()); - IActionResult a = await api.Get(); - - /// utilisation du nuggets fluentAssertion - //Assert.IsNotNull(a); - a.Should().NotBeNull(); - //Assert.AreEqual(list,((OkObjectResult)a).Value); - var aObject = a as OkObjectResult; - aObject.Should().NotBeNull(); - var championresult = aObject.Value as IEnumerable; - list.Should().BeEquivalentTo(championresult); - } - - [TestMethod] - public async Task TestPostValid() - { - ChampionsController api = new ChampionsController(new StubData()); - IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon")); - Assert.IsNotNull(a); - ChampionDTO champ = new ChampionDTO("nom", "bio", "icon"); - //Assert.AreEqual(champ,((CreatedAtActionResult)a).Value); - } - - } -} \ No newline at end of file From 7a15311d098c536a165e0b57666897eb4e74ac2e Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Sun, 12 Mar 2023 18:03:36 +0100 Subject: [PATCH 7/9] =?UTF-8?q?Ajout=20de=20la=20db=20stubb=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/EntityFramework/ChampionEntity.cs | 8 +- .../EntityFramework/EntityFramework.csproj | 4 + .../EntityFramework/LoLDBContextWithStub.cs | 25 ++++++ Sources/EntityFramework/LoLDbContext.cs | 6 +- .../EntityFramework/Mapper/ChampionMapper.cs | 16 ++++ .../20230301152530_SkillMigration.Designer.cs | 85 ------------------ .../20230301152530_SkillMigration.cs | 63 ------------- .../20230312170120_stubMig.Designer.cs | 83 +++++++++++++++++ .../Migrations/20230312170120_stubMig.cs | 49 ++++++++++ .../LoLDBContextWithStubModelSnapshot.cs | 80 +++++++++++++++++ .../Migrations/LoLDbContextModelSnapshot.cs | 82 ----------------- Sources/EntityFramework/champion.db | Bin 32768 -> 20480 bytes Sources/LeagueOfLegends.sln | 3 + 13 files changed, 267 insertions(+), 237 deletions(-) create mode 100644 Sources/EntityFramework/LoLDBContextWithStub.cs create mode 100644 Sources/EntityFramework/Mapper/ChampionMapper.cs delete mode 100644 Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs delete mode 100644 Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs create mode 100644 Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs create mode 100644 Sources/EntityFramework/Migrations/20230312170120_stubMig.cs create mode 100644 Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs delete mode 100644 Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs index 5d2c455..d672964 100644 --- a/Sources/EntityFramework/ChampionEntity.cs +++ b/Sources/EntityFramework/ChampionEntity.cs @@ -13,11 +13,11 @@ namespace EntityFramework [Table("Champion")] public class ChampionEntity { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int Id { get; set; } + //[Key] + //[DatabaseGenerated(DatabaseGeneratedOption.Identity)] + //public int Id { get; set; } - [Required] + [Key] [MaxLength(50)] public string Name { get; set; } diff --git a/Sources/EntityFramework/EntityFramework.csproj b/Sources/EntityFramework/EntityFramework.csproj index 66899d0..2d1f7fc 100644 --- a/Sources/EntityFramework/EntityFramework.csproj +++ b/Sources/EntityFramework/EntityFramework.csproj @@ -17,4 +17,8 @@ + + + + diff --git a/Sources/EntityFramework/LoLDBContextWithStub.cs b/Sources/EntityFramework/LoLDBContextWithStub.cs new file mode 100644 index 0000000..7379162 --- /dev/null +++ b/Sources/EntityFramework/LoLDBContextWithStub.cs @@ -0,0 +1,25 @@ +using EntityFramework.Mapper; +using Microsoft.EntityFrameworkCore; +using StubLib; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + public class LoLDBContextWithStub : LoLDbContext + { + protected override async void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + var stub = new StubData.ChampionsManager(new StubData()); + var list = await stub.GetItems(0, await stub.GetNbItems()); + modelBuilder.Entity().HasData( + list.Select(champion => champion.ToEntity()) + ); + } + } +} diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index 9fa1567..7d61851 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -29,11 +29,11 @@ namespace EntityFramework protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasKey(entity => entity.Id); + modelBuilder.Entity().HasKey(entity => entity.Name); modelBuilder.Entity().ToTable("Champion"); - modelBuilder.Entity().Property(entity => entity.Id) - .ValueGeneratedOnAdd(); + //modelBuilder.Entity().Property(entity => entity.Id) + // .ValueGeneratedOnAdd(); modelBuilder.Entity().Property(entity => entity.Name) .IsRequired() diff --git a/Sources/EntityFramework/Mapper/ChampionMapper.cs b/Sources/EntityFramework/Mapper/ChampionMapper.cs new file mode 100644 index 0000000..862264d --- /dev/null +++ b/Sources/EntityFramework/Mapper/ChampionMapper.cs @@ -0,0 +1,16 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework.Mapper +{ + public static class ChampionMapper + { + public static ChampionEntity ToEntity(this Champion champion) { + return new ChampionEntity(champion.Name, champion.Bio, champion.Icon); + } + } +} diff --git a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs b/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs deleted file mode 100644 index 94bb55c..0000000 --- a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -using System; -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDbContext))] - [Migration("20230301152530_SkillMigration")] - partial class SkillMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champion", (string)null); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("ChampionEntityId") - .HasColumnType("INTEGER"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("ChampionEntityId"); - - b.ToTable("Skill"); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.HasOne("EntityFramework.ChampionEntity", null) - .WithMany("Skills") - .HasForeignKey("ChampionEntityId"); - }); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Navigation("Skills"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs b/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs deleted file mode 100644 index ce0154c..0000000 --- a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramework.Migrations -{ - /// - public partial class SkillMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champion", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), - Bio = table.Column(type: "string", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champion", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Skill", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Type = table.Column(type: "INTEGER", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - ChampionEntityId = table.Column(type: "INTEGER", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Skill", x => x.Name); - table.ForeignKey( - name: "FK_Skill_Champion_ChampionEntityId", - column: x => x.ChampionEntityId, - principalTable: "Champion", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Skill_ChampionEntityId", - table: "Skill", - column: "ChampionEntityId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Skill"); - - migrationBuilder.DropTable( - name: "Champion"); - } - } -} diff --git a/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs b/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs new file mode 100644 index 0000000..2b24874 --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs @@ -0,0 +1,83 @@ +// +using EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramework.Migrations +{ + [DbContext(typeof(LoLDBContextWithStub))] + [Migration("20230312170120_stubMig")] + partial class stubMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("string") + .HasColumnName("Bio"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champion", (string)null); + + b.HasData( + new + { + Name = "Akali", + Bio = "", + Icon = "" + }, + new + { + Name = "Aatrox", + Bio = "", + Icon = "" + }, + new + { + Name = "Ahri", + Bio = "", + Icon = "" + }, + new + { + Name = "Akshan", + Bio = "", + Icon = "" + }, + new + { + Name = "Bard", + Bio = "", + Icon = "" + }, + new + { + Name = "Alistar", + Bio = "", + Icon = "" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs b/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs new file mode 100644 index 0000000..3323fa4 --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs @@ -0,0 +1,49 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace EntityFramework.Migrations +{ + /// + public partial class stubMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champion", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Bio = table.Column(type: "string", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champion", x => x.Name); + }); + + migrationBuilder.InsertData( + table: "Champion", + columns: new[] { "Name", "Bio", "Icon" }, + values: new object[,] + { + { "Aatrox", "", "" }, + { "Ahri", "", "" }, + { "Akali", "", "" }, + { "Akshan", "", "" }, + { "Alistar", "", "" }, + { "Bard", "", "" } + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champion"); + } + } +} diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs new file mode 100644 index 0000000..ba61c51 --- /dev/null +++ b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs @@ -0,0 +1,80 @@ +// +using EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramework.Migrations +{ + [DbContext(typeof(LoLDBContextWithStub))] + partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("string") + .HasColumnName("Bio"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champion", (string)null); + + b.HasData( + new + { + Name = "Akali", + Bio = "", + Icon = "" + }, + new + { + Name = "Aatrox", + Bio = "", + Icon = "" + }, + new + { + Name = "Ahri", + Bio = "", + Icon = "" + }, + new + { + Name = "Akshan", + Bio = "", + Icon = "" + }, + new + { + Name = "Bard", + Bio = "", + Icon = "" + }, + new + { + Name = "Alistar", + Bio = "", + Icon = "" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs deleted file mode 100644 index 0abeee1..0000000 --- a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -using System; -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDbContext))] - partial class LoLDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champion", (string)null); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("ChampionEntityId") - .HasColumnType("INTEGER"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("ChampionEntityId"); - - b.ToTable("Skill"); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.HasOne("EntityFramework.ChampionEntity", null) - .WithMany("Skills") - .HasForeignKey("ChampionEntityId"); - }); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Navigation("Skills"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db index 662e97286ee8cfaef248c402272a5a70116a24d4..b0ff12d7b320d5866aecbae454397eb8c1f38820 100644 GIT binary patch delta 375 zcmZo@U}{*vI6q^mChFMmu<*WT;Jd`XmiIm1!p(vL)x2Dd`poR&va*a#hLiZr zCa3c#Pmbafojiw!WAXw%BQ|{&HgRX!$@RPv!p<3qxdoZ|dGUrY7VG9qd?t)64;c6# zY!-C5#;+yE$ZRQYWME`$U~Fh)Xl`I=WDs9mQkvwOnQpFUpl8GdbPXf_GY0-=K=pU{ z^(2`sIk79}1*&A@-^0NFh5r@*eg4b*$N2XE-MfN6f`g4kl$X~ju_%R`l|`DD*D)uv zxFoTNi-koJ$jL6wNX+A8W)TOm6LT^-m_Vu>Gm0{~7{Lk>ON#OYBVbsvm_(LWEM_laUc_DFf&Lc$Xq5)W=T#* Gu(1HqxLr;F literal 32768 zcmeI)?N8G{90%~bb`OBeLlV+pGQ2b~aeqFw10B8(_n=B=QpV zukf{R{Ri~D?|kDseWUM zY;DziULYexQOGsU2_cHu2E-Pnn8*ZMlxUPWX0MRx>iHD=L6T=)k+W~vi`4hj^Wki2 zSA0Z*00bZa0SG_<0uX=z1pZ#YOD46e8r@5~jk@#5T&=EbxSN~R*$1_)ZMWGl8oulA znsr$^Fk3N-w!uwn&RFI8k(G5`wzw{v==_r2-ItzuT#6?(O`}gY{My}3N7j^YiSP_| z@%o~1&_!y9i=rU6l_@O9t9lX>KQJ4}fGka@lQcI`llep|N0*dyrL%sYy z`YZ<5u$Ll(1OW&@00Izz00bZa0SG_< z0uX?}2?|Wa;v}8E&}eSSr$FwyO}Tf)Lk}`@PK}eXu`%EA{Aim{{?LT>G--eT|0`i% zPjG5D6$Bsv0SG_<0uX=z1Rwwb2tWV=|5#v{s%aYiI72MB{#V&+!oINgVuu6)2tWV= z5P$##AOHafKmY;|fWUt%FsjDKsYd1Z0t!l9{32#S8C4F-@@i0)S4L=jd|<3yFBcRk z!Snwr`$*V#_DSrJAOHafKmY;|fB*y_009U<00Iy=g#ttBcz9bt?PT-HpgKM%Zx-a* y*Z=#3{bb+R{wbUwh717+KmY;|fB*y_009U<00IzzK(|0#rBqSnyAo6Bpz;eKgSiI) diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 5049af2..a5d27bb 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -18,6 +18,9 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{E39C3FBC-DE5E-4DAF-945A-98CE4ADE54D9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework", "EntityFramework\EntityFramework.csproj", "{23483395-5091-4956-822F-17234E8C9E5C}" + ProjectSection(ProjectDependencies) = postProject + {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csproj", "{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}" EndProject From 2e31daa53b58fdca5115fc65310d47b33c0d865f Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Sun, 12 Mar 2023 18:11:36 +0100 Subject: [PATCH 8/9] fix tests --- Sources/EF_UT/EntityTest.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/EF_UT/EntityTest.cs b/Sources/EF_UT/EntityTest.cs index d1f87b5..4122418 100644 --- a/Sources/EF_UT/EntityTest.cs +++ b/Sources/EF_UT/EntityTest.cs @@ -54,8 +54,8 @@ namespace EF_UT //prepares the database with one instance of the context using (var context = new LoLDbContext(options)) { - ChampionEntity chewie = new ChampionEntity("Chewbacca", "", ""); - ChampionEntity yoda = new ChampionEntity("Yoda", "", ""); + ChampionEntity chewie = new ChampionEntity("Chewbacca", "ewa", ""); + ChampionEntity yoda = new ChampionEntity("Yoda", "wewo", ""); ChampionEntity ewok = new ChampionEntity("Ewok", "", ""); context.Add(chewie); @@ -67,23 +67,23 @@ namespace EF_UT //prepares the database with one instance of the context using (var context = new LoLDbContext(options)) { - string NameToFind = "ew"; - Assert.AreEqual(2, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count()); - NameToFind = "ewo"; - Assert.AreEqual(1, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count()); - var ewok = context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).First(); - ewok.Name = "Wicket"; + string BioToFind = "ew"; + Assert.AreEqual(2, context.Champions.Where(n => n.Bio.ToLower().Contains(BioToFind)).Count()); + BioToFind = "ewo"; + Assert.AreEqual(1, context.Champions.Where(n => n.Bio.ToLower().Contains(BioToFind)).Count()); + var ewok = context.Champions.Where(n => n.Bio.ToLower().Contains(BioToFind)).First(); + ewok.Bio = "Wicket"; context.SaveChanges(); } //prepares the database with one instance of the context - using (var context = new LoLDbContext(options)) - { - string NameToFind = "ew"; - Assert.AreEqual(1, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count()); - NameToFind = "wick"; - Assert.AreEqual(1, context.Champions.Where(n => n.Name.ToLower().Contains(NameToFind)).Count()); - } + //using (var context = new LoLDbContext(options)) + //{ + // string NameToFind = "ew"; + // Assert.AreEqual(1, context.Champions.Where(n => n.Bio.ToLower().Contains(NameToFind)).Count()); + // NameToFind = "wick"; + // Assert.AreEqual(1, context.Champions.Where(n => n.Bio.ToLower().Contains(NameToFind)).Count()); + //} } } } From 0260d4afd0328909204459ba5125aaf1f82f0f25 Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Mon, 13 Mar 2023 16:23:27 +0100 Subject: [PATCH 9/9] :bookmark: fin du versionning ! 3 versions differentes : V1, V2, V2.2 ! --- .../ChampionsControllerVersioned.cs | 140 +++++++++--------- Sources/API_LoL/Program.cs | 6 + Sources/API_LoL/SwaggerOptions.cs | 61 ++++++++ 3 files changed, 138 insertions(+), 69 deletions(-) create mode 100644 Sources/API_LoL/SwaggerOptions.cs diff --git a/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs b/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs index e8b3a24..87598d9 100644 --- a/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs +++ b/Sources/API_LoL/Controllers/ChampionsControllerVersioned.cs @@ -22,84 +22,86 @@ namespace API_LoL.Controllers // GET api//5 - [HttpGet] - public async Task Get(String? name = null, String? skill = null, String? characteristic = null, int index = 0, int size = 10) - { - if (size - index > 10) - { - return BadRequest(); - } - if (!string.IsNullOrEmpty(name)) - { - var list = await ChampionsManager.GetItemsByName(name, index, size); - if (list.Count() != 0) - { - return Ok(list.Select(champion => champion?.ToDTO())); - } - else { return NoContent(); } - } - else if (!string.IsNullOrEmpty(skill)) - { - var list = await ChampionsManager.GetItemsBySkill(skill, index, size); - if (list.Count() != 0) - { - return Ok(list.Select(champion => champion?.ToDTO())); - } - else { return NoContent(); } - } - else if (!string.IsNullOrEmpty(characteristic)) - { - var list = await ChampionsManager.GetItems(index, size); - if (list.Count() != 0) - { - return Ok(list.Select(champion => champion?.ToDTO())); - } - else { return NoContent(); } - } - else - { - var list = await ChampionsManager.GetItems(index, size); - if (list.Count() != 0) - { - return Ok(list.Select(champion => champion?.ToDTO())); - } - else { return NoContent(); } - } - } + //[HttpGet] + //public async Task Get(String? name = null, String? skill = null, String? characteristic = null, int index = 0, int size = 10) + //{ + // if (size - index > 10) + // { + // return BadRequest(); + // } + // if (!string.IsNullOrEmpty(name)) + // { + // var list = await ChampionsManager.GetItemsByName(name, index, size); + // if (list.Count() != 0) + // { + // return Ok(list.Select(champion => champion?.ToDTO())); + // } + // else { return NoContent(); } + // } + // else if (!string.IsNullOrEmpty(skill)) + // { + // var list = await ChampionsManager.GetItemsBySkill(skill, index, size); + // if (list.Count() != 0) + // { + // return Ok(list.Select(champion => champion?.ToDTO())); + // } + // else { return NoContent(); } + // } + // else if (!string.IsNullOrEmpty(characteristic)) + // { + // var list = await ChampionsManager.GetItems(index, size); + // if (list.Count() != 0) + // { + // return Ok(list.Select(champion => champion?.ToDTO())); + // } + // else { return NoContent(); } + // } + // else + // { + // var list = await ChampionsManager.GetItems(index, size); + // if (list.Count() != 0) + // { + // return Ok(list.Select(champion => champion?.ToDTO())); + // } + // else { return NoContent(); } + // } + //} - // POST api/ - [HttpPost] - public async Task Post(ChampionDTO champion) - { - if (champion == null) - { - return UnprocessableEntity(); - } - else - { - await ChampionsManager.AddItem(champion.ToChampion()); - return CreatedAtAction("Post", champion); - } - } + //// POST api/ + //[HttpPost] + //public async Task Post(ChampionDTO champion) + //{ + // if (champion == null) + // { + // return UnprocessableEntity(); + // } + // else + // { + // await ChampionsManager.AddItem(champion.ToChampion()); + // return CreatedAtAction("Post", champion); + // } + //} - // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) - { - } + //// PUT api//5 + //[HttpPut("{id}")] + //public void Put(int id, [FromBody] string value) + //{ + //} - // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } + //// DELETE api//5 + //[HttpDelete("{id}")] + //public void Delete(int id) + //{ + //} ///---------- Versioning ----------/// - [HttpGet] + [HttpGet, MapToApiVersion("2.0")] public string GetThatOnlySayHello() => "Hello v2.0!"; + + //! FIXME : not working, mais avec la version 2.0 ca marche ! [HttpGet, MapToApiVersion("2.2")] public string GetThatOnlySayHelloV2() => "Hello but i'm from v2.2!"; } diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index b8f9f47..c192eac 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -1,3 +1,4 @@ +using API_LoL; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Versioning; using Model; @@ -26,6 +27,8 @@ builder.Services.AddVersionedApiExplorer(setup => builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.ConfigureOptions(); + builder.Services.AddApiVersioning(o => o.ApiVersionReader = new UrlSegmentApiVersionReader()); @@ -36,6 +39,9 @@ builder.Services.AddControllers(); builder.Services.AddScoped(); + + + var app = builder.Build(); var apiVersionDescriptionProvider = app.Services.GetRequiredService(); diff --git a/Sources/API_LoL/SwaggerOptions.cs b/Sources/API_LoL/SwaggerOptions.cs new file mode 100644 index 0000000..46ad759 --- /dev/null +++ b/Sources/API_LoL/SwaggerOptions.cs @@ -0,0 +1,61 @@ +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace API_LoL +{ + public class ConfigureSwaggerOptions : IConfigureNamedOptions + { + private readonly IApiVersionDescriptionProvider _provider; + + public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) + { + _provider = provider; + } + + /// + /// Configure each API discovered for Swagger Documentation + /// + /// + public void Configure(SwaggerGenOptions options) + { + // add swagger document for every API version discovered + foreach (var description in _provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateVersionInfo(description)); + } + } + + /// + /// Configure Swagger Options. Inherited from the Interface + /// + /// + /// + public void Configure(string name, SwaggerGenOptions options) + { + Configure(options); + } + + /// + /// Create information about the version of the API + /// + /// + /// Information about the API + private OpenApiInfo CreateVersionInfo(ApiVersionDescription desc) + { + var info = new OpenApiInfo() + { + Title = ".NET Core (.NET 6) Web API", + Version = desc.ApiVersion.ToString() + }; + + if (desc.IsDeprecated) + { + info.Description += " This API version has been deprecated. Please use one of the new APIs available from the explorer."; + } + + return info; + } + } +}