diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index d3190ef..ba8264e 100644 Binary files a/.vs/LolProject/v17/.suo and b/.vs/LolProject/v17/.suo differ diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs index e1f2dda..ad2f3f2 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs @@ -32,6 +32,10 @@ namespace ApiLol.Controllers { var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems())) .Select(x => x.ToDto()); + if(dtos == null) + { + return NotFound(); + } return Ok(dtos); } @@ -40,21 +44,21 @@ namespace ApiLol.Controllers public async Task Post([FromBody] ChampionDto champion) { return CreatedAtAction(nameof(Get), - await _manager.ChampionsMgr.AddItem(champion.ToModel())); + (await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto()); } - // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) +/* // PUT api//5 + [HttpPut("{name}")] + public async void Put(string name, [FromBody] ChampionDto champion) { - - } + return Ok(await _manager.ChampionsMgr.UpdateItem(, champion.ToModel())); + }*/ // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) + [HttpDelete] + public async Task Delete([FromBody] ChampionDto champion) { - + return Ok(await _manager.ChampionsMgr.DeleteItem(champion.ToModel())); } } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs index 97fe7ca..32ab8a7 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs @@ -10,12 +10,16 @@ namespace ApiLol.Mapper return new ChampionDto() { Name = champion.Name, + Bio = champion.Bio, }; } public static Champion ToModel(this ChampionDto championDto) { - + return new Champion(championDto.Name) + { + Bio = championDto.Bio, + }; } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs new file mode 100644 index 0000000..fcd88a6 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs @@ -0,0 +1,25 @@ +using DTO; +using Model; + +namespace ApiLol.Mapper +{ + public static class RuneMapper + { + public static RuneDto ToDto(this Rune rune) + { + return new RuneDto() + { + Name = rune.Name, + Description = rune.Description, + }; + } + +/* public static Rune ToModel(this RuneDto rune) + { + return new Rune(rune.Name) + { + Description = rune.Description, + }; + }*/ + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs new file mode 100644 index 0000000..768caf7 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs @@ -0,0 +1,25 @@ +using DTO; +using Model; + +namespace ApiLol.Mapper +{ + public static class SkillMapper + { + public static SkillDto ToDto(this Skill skill) + { + return new SkillDto() + { + Name = skill.Name, + Description = skill.Description, + }; + } + +/* public static Skill ToModel(this SkillDto skill) + { + return new Skill(skill.Name) + { + Description = skill.Description + }; + }*/ + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Program.cs b/src/EntityFramework_LoL/Sources/ApiLol/Program.cs index 5952afd..e6ed0a5 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Program.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Program.cs @@ -9,7 +9,7 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddScoped(); +builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs b/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs index ff63eb9..2fa8957 100644 --- a/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs +++ b/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs @@ -28,7 +28,7 @@ namespace Client await _httpClient.PostAsJsonAsync(ApiChampions, champion); } - public async void Delete(ChampionDto champion) +/* public async void Delete(ChampionDto champion) { await _httpClient.DeleteAsync(champion); } @@ -36,7 +36,7 @@ namespace Client public async void Update(ChampionDto champion) { await _httpClient.PutAsJsonAsync(ApiChampions, champion); - } + }*/ } } diff --git a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs index 5c7ecf2..f19a03b 100644 --- a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs +++ b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs @@ -3,5 +3,6 @@ public class ChampionDto { public string Name { get; set; } + public string Bio { get; set; } } } \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/DTO/RuneDto.cs b/src/EntityFramework_LoL/Sources/DTO/RuneDto.cs new file mode 100644 index 0000000..f5afb80 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/RuneDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class RuneDto + { + public string Name { get; set; } + public string Description { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/SkillDto.cs b/src/EntityFramework_LoL/Sources/DTO/SkillDto.cs new file mode 100644 index 0000000..77372ab --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/SkillDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkillDto + { + public string Name { get; set; } + public string Description { get; set; } + } +} diff --git a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs index b7468b5..a0b976c 100644 --- a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs @@ -10,7 +10,7 @@ namespace ApiTests public class ChampionsControllerTest { private readonly StubData stub; - private readonly ChampionsControllerTest champs; + private readonly ChampionsController champs; public ChampionsControllerTest() { stub = new StubData(); @@ -18,21 +18,21 @@ namespace ApiTests } [TestMethod] - public async void TestGetChampions() + public async Task TestGetChampions() { //Arrange //Act - var champion = champs.Get(); + var champion = await champs.Get(); //Assert var objectResult = champion as OkObjectResult; Assert.IsNotNull(objectResult); - var champions = objectResult?.Value as IEnumerable; + var champions = objectResult?.Value as IEnumerable; Assert.IsNotNull(champions); - Assert.AreEqual(champions.Count(), await stub.ChampionsMgr.GetItems(0,5).Count()); + Assert.AreEqual(champions.Count(), await stub.ChampionsMgr.GetNbItems()); } @@ -42,17 +42,18 @@ namespace ApiTests //Arange var ChampionDto = new ChampionDto { - Name = "Sylas" + Name = "Sylas", + Bio = "Good" }; //Act var championsResult = await champs.Post(ChampionDto); //Assert - var objectResult = championsResult as OkObjectResult; + var objectResult = championsResult as CreatedAtActionResult; Assert.IsNotNull(objectResult); - var champions = objectResult?.Value as IEnumerable; + var champions = objectResult?.Value as Champion; Assert.IsNotNull(champions); }