diff --git a/Sources/APILOL/APILOL.csproj b/Sources/APILOL/APILOL.csproj index 60bf9ea..3b42408 100644 --- a/Sources/APILOL/APILOL.csproj +++ b/Sources/APILOL/APILOL.csproj @@ -10,4 +10,10 @@ + + + + + + diff --git a/Sources/APILOL/Controllers/ChampionsController.cs b/Sources/APILOL/Controllers/ChampionsController.cs new file mode 100644 index 0000000..08f558b --- /dev/null +++ b/Sources/APILOL/Controllers/ChampionsController.cs @@ -0,0 +1,73 @@ +using APILOL.Mapper; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; +using System; +using System.Xml.Linq; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace APILOL.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ChampionsController : ControllerBase + { + + IChampionsManager managerChampions; + + public ChampionsController(IDataManager manager) + { + managerChampions = manager.ChampionsMgr; + } + + + // GET: api/ + [HttpGet] + + public async Task Get() + { + IEnumerable championDTOs = (await managerChampions.GetItems(0, await managerChampions.GetNbItems())).Select(x => x.ToDTO()); + + if (championDTOs != null) + { + return Ok(championDTOs); + } + return NotFound(); + } + + // GET api//5 + [HttpGet("{name}")] + public async Task GetAsync(String name) + { + IEnumerable champ = await managerChampions.GetItemsByName(name, 0, await managerChampions.GetNbItems()); + if (champ.Count() != 0) + { + return Ok(champ.First().ToDTO()); + } + return NotFound(); + } + + // POST api/ + [HttpPost] + public async Task Post([FromBody] ChampionDTO champion) + { + return CreatedAtAction(nameof(Get), await managerChampions.AddItem(champion.ToModel())); + + } + + // PUT api//5 + [HttpPut("{name}")] + public async void Put(String name, [FromBody] ChampionDTO champion) + { + + } + + // DELETE api//5 + [HttpDelete("{id}")] + public async void Delete(int id) + { + } + } +} diff --git a/Sources/APILOL/Mapper/ChampionMapper.cs b/Sources/APILOL/Mapper/ChampionMapper.cs new file mode 100644 index 0000000..561a96c --- /dev/null +++ b/Sources/APILOL/Mapper/ChampionMapper.cs @@ -0,0 +1,20 @@ +using DTO; +using Model; +using System.Buffers.Text; +using System.Xml.Linq; + +namespace APILOL.Mapper +{ + public static class ChampionMapper + { + public static ChampionDTO ToDTO(this Champion champ) + { + return new ChampionDTO() { Name = champ.Name, Bio = champ.Bio, Icon = champ.Icon, Image = champ.Image.Base64 }; + } + + public static Champion ToModel(this ChampionDTO champ) + { + return new Champion(champ.Name,icon: champ.Icon, image: champ.Icon, bio: champ.Bio); + } + } +} diff --git a/Sources/APILOL/Program.cs b/Sources/APILOL/Program.cs index 48863a6..440cdf0 100644 --- a/Sources/APILOL/Program.cs +++ b/Sources/APILOL/Program.cs @@ -1,7 +1,10 @@ +using Model; +using StubLib; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. - +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); diff --git a/Sources/ChampionControllerTest.cs b/Sources/ChampionControllerTest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs new file mode 100644 index 0000000..a66c8cc --- /dev/null +++ b/Sources/DTO/ChampionDTO.cs @@ -0,0 +1,16 @@ +namespace DTO +{ + public class ChampionDTO + { + public string Name { get; set; } + public string Bio { get; set; } + public string Icon { get; set; } + + public string Image { get; set; } + + + + + + } +} \ No newline at end of file diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Sources/DTO/DTO.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index fe317f6..1a7e6bf 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -15,7 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "APILOL", "APILOL\APILOL.csproj", "{88538F30-9D26-4A70-88FD-12BA05576E39}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APILOL", "APILOL\APILOL.csproj", "{88538F30-9D26-4A70-88FD-12BA05576E39}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{2124E1DB-1E6D-4FCE-9F34-53457C374394}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,6 +45,10 @@ Global {88538F30-9D26-4A70-88FD-12BA05576E39}.Debug|Any CPU.Build.0 = Debug|Any CPU {88538F30-9D26-4A70-88FD-12BA05576E39}.Release|Any CPU.ActiveCfg = Release|Any CPU {88538F30-9D26-4A70-88FD-12BA05576E39}.Release|Any CPU.Build.0 = Release|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE