diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj
index 1df2c4a..a5a4234 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj
@@ -9,13 +9,15 @@
+
+
+
-
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs
deleted file mode 100644
index ce3fe29..0000000
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs
+++ /dev/null
@@ -1,189 +0,0 @@
-using API_LoL_Project.Mapper;
-using API_LoL_Project.Middleware;
-using DTO;
-using Microsoft.AspNetCore.Mvc;
-using Model;
-using StubLib;
-using System.Xml.Linq;
-
-// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
-
-namespace API_LoL_Project.Controllers
-{
- [Route("api/[controller]")]
- [ApiController]
- public class ChampionsController : ControllerBase
- {
- public IChampionsManager dataManager;
- private readonly ILogger _logger;
-
- /* public ChampionsController(IChampionsManager dataManager)
- {
- this.dataManager = dataManager;
- }*/
- public ChampionsController(IDataManager dataManager, ILogger logger)
- {
- this.dataManager = dataManager.ChampionsMgr;
- this._logger = logger;
- }
-
-
-
- // GET: api/
- [HttpGet]
- public async Task>> Get([FromQuery] Request.PageRequest request)
- {
- try
- {
- var totalcount = await dataManager.GetNbItems();
- if (request.count + request.index > totalcount)
- {
- _logger.LogWarning("No chamions found with Id");
- return BadRequest("No chamions found with Id ");
- }
- _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);;
- var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, request.descending);
- IEnumerable res = champions.Select(c => c.ToDTO());
- if (res.Count() <= 0 || res == null)
- {
- _logger.LogWarning("No chamions found with Id");
- return BadRequest("No chamions found with Id ");
- }
- return Ok(res);
- }
- catch (Exception e)
- {
- return BadRequest(e.Message);
-
- }
-
-
- }
-
-
-
- // GET api//5
- [HttpGet("{name}")]
- public async Task> GetChampionsByName(string name)
- {
- try
- {
-
- var champion = await dataManager
- .GetItemsByName(name, 0, await dataManager.GetNbItems());
- _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
- ChampionDTO res = champion.First().ToDTO();
- if (res == null)
- {
- _logger.LogWarning("No chamions found with {name}", name); ;
- return NotFound();
- }
- return Ok(res);
-
- }
- catch (Exception e)
- {
- return BadRequest(e.Message);
-
- }
- }
-
-
- // POST api/
- [HttpPost]
- public async Task Post([FromBody] ChampionDTO value)
- {
- try
- {
- var newChampion = value.ToModel();
- await dataManager.AddItem(newChampion);
- return CreatedAtAction(nameof(Get), newChampion) ;
- }
- catch (Exception e)
- {
- return BadRequest(e.Message);
-
- }
-
- }
-
- // PUT api//5
- [HttpPut("{name}")]
- public async Task Put(string name, [FromBody] ChampionDTO value)
- {
-
-
- try
- {
- var champion = await dataManager
- .GetItemsByName(name, 0, await dataManager.GetNbItems());
- await dataManager.UpdateItem(champion.First(), value.ToModel());
- return Ok();
- }
- catch(Exception e)
- {
- return BadRequest(e.Message);
- }
- }
-
- // DELETE api//5
- [HttpDelete("{name}")]
- public async Task Delete(string name)
- {
- try
- {
- var champion = await dataManager
- .GetItemsByName(name, 0, await dataManager.GetNbItems());
- if (champion != null) await dataManager.DeleteItem(champion.First());
- else
- {
- return NotFound();
- }
- return Ok();
- }
- catch (Exception e)
- {
- return BadRequest(e.Message);
- }
-
- }
-
- /* [HttpGet]
- public async Task NbChampions()
- {
- var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
- IEnumerable res = champions.Select(c => c.toDTO());
- return Ok(res);
-
- }*/
-
- [HttpGet("/{name}/skins")]
- public async Task> GetChampionsSkins(string name)
- {
- var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
- //skinsDTO
- IEnumerable res = champions.First().Skins;
-
- return Ok(res);
- }
-
- [HttpGet("/{name}/skills")]
- public async Task> GetChampionsSkills(string name)
- {
- var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
- //SkillDTO
- IEnumerable res = champions.First().Skills;
-
- return Ok(res);
- }
-
- /*[HttpGet("/{name}/skins")]
- public async Task NbChampions()
- {
- var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
- IEnumerable res = champions.Select(c => c.toDTO());
- return Ok(res);
-
- }*/
- }
-}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs
index 9ff2a11..69f2237 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs
@@ -3,8 +3,10 @@
public class PageRequest
{
public string? orderingPropertyName { get; set; } = null;
- public bool descending { get; set; } = false;
- public int index { get; set; } = 1;
+ public bool? descending { get; set; } = false;
+ public int index { get; set; } = 0;
public int count { get; set; } = 1;
+
+
}
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs
new file mode 100644
index 0000000..3ef451d
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs
@@ -0,0 +1,22 @@
+namespace API_LoL_Project.Controllers.Response
+{
+ public class EndPointLink
+ {
+ public string Href { get; set; }
+ public string Rel { get; set; }
+ public string Method { get; set; }
+ public EndPointLink()
+ {
+ }
+ public EndPointLink(string href, string rel, string method)
+ {
+ Href = href;
+ Rel = rel;
+ Method = method;
+ }
+ public static EndPointLink To(string href, string rel = "self", string method = "GET")
+ {
+ return new EndPointLink { Href = href, Rel = rel, Method = method };
+ }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs
index f75a599..0a3055f 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs
@@ -1,6 +1,22 @@
-namespace API_LoL_Project.Controllers.Response
+using API_LoL_Project.Middleware;
+
+namespace API_LoL_Project.Controllers.Response
{
- public class PageResponse
+ public class PageResponse
{
+ public IEnumerable> Data { get; set; }
+ public int Index { get; set; } = 1;
+ public int TotalCount { get; set; } = 1;
+ public int Count { get; set; } = 1;
+
+
+ public PageResponse(IEnumerable> data, int indexRequested, int countRequested, int totalCount)
+ {
+ this.Data = data;
+ this.Index = indexRequested;
+ this.TotalCount = totalCount;
+ this.Count = countRequested;
+ }
}
}
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs
index f22363b..2bef43b 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs
@@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using Model;
using API_LoL_Project.Mapper;
+using API_LoL_Project.Controllers.Response;
+using API_LoL_Project.Middleware;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -10,111 +12,166 @@ namespace API_LoL_Project.Controllers
{
[Route("api/[controller]")]
[ApiController]
+
public class RuneController : ControllerBase
{
- /*public IRunesManager runesManager;
+ public IRunesManager dataManager;
// you should create a custom logger to be prety
private readonly ILogger _logger;
public RuneController(IDataManager dataManager, ILogger logger)
{
- this.runesManager = dataManager.RunesMgr;
+ this.dataManager = dataManager.RunesMgr;
this._logger = logger;
}
- *//*// GET: api/
+ /*// GET: api/
[HttpGet]
- public async Task> Get()
+ public async Task>> GetAllRunes([FromQuery] Request.PageRequest request)
{
try
{
- var runes = await runesManager.GetItems(0, await runesManager.GetNbItems());
- IEnumerable res = runes.Select(c => c.toDTO());
- return Ok(res);
- }
- catch (Exception e)
- {
- _logger.LogInformation("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
- return BadRequest(e.Message);
-
- }
- }*//*
-
- // GET: api/
- [HttpGet]
- public async Task>> Get([FromQuery] Request.PageRequest request)
- {
- try
- {
- var totalcount = await runesManager.GetNbItems();
- if (request.count + request.index > totalcount)
+ var totalcount = await dataManager.GetNbItems();
+ if (request.count * request.index >= totalcount)
{
- _logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
- return BadRequest("to many rows ask the max is " + totalcount) ;
+ _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount);
+ return BadRequest("To many object is asked the max is : " + totalcount);
}
- _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
-
- var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName,(request.descending == null ? false : (bool)request.descending));
+ _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetAllRunes), request); ;
+ var runes = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable res = runes.Select(c => c.toDTO());
- if (res.Count() >= 0 || res == null)
+ if (res.Count() <= 0 || res == null)
{
- _logger.LogWarning("No runes found with Id");
- return BadRequest("No runes found with Id ");
+ _logger.LogError("No runes found the total count is {totalcount} ", totalcount);
+ return BadRequest("No runes found : totalcount is : " + totalcount);
}
- return Ok(res);
+
+ var respList = res.Select(r => new LolResponce
+ (
+ r,
+ new List
+ {
+ EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self","POST"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
+ }
+ ));
+
+ var pageResponse = new PageResponse(respList, request.index, request.count, totalcount);
+
+ return Ok(pageResponse);
}
catch (Exception e)
{
- _logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
+ _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message);
return BadRequest(e.Message);
}
+ }
+ */
- }
+ // GET: api/
+ /* [HttpGet]
+ public async Task>> Get([FromQuery] Request.PageRequest request)
+ {
+ try
+ {
+ var totalcount = await runesManager.GetNbItems();
+ if (request.count + request.index > totalcount)
+ {
+ _logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
+ return BadRequest("to many rows ask the max is " + totalcount);
+ }
+ _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
+
+
+ var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
+ IEnumerable res = runes.Select(c => c.toDTO());
+ if (res.Count() >= 0 || res == null)
+ {
+ _logger.LogWarning("No runes found with Id");
+ return BadRequest("No runes found with Id ");
+ }
+ return Ok(res);
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
+ return BadRequest(e.Message);
+
+ }
+
+
+ }
+ */
+ /*
+ [HttpGet("{name}")]
+ public async Task>> GetRuneByName(string name)
+ {
+ try
+ {
+ var rune = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name);
+ RuneDTO res = rune.First().toDTO();
+
+ if (res == null)
+ {
+ _logger.LogWarning("No runes found with {name}", name); ;
+ return NotFound();
+ }
+ var links = new List
+ {
+ EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
+ };
+
+ var response = new LolResponce(res, links);
+ return Ok(response);
- // GET api//5
- [HttpGet("{id}")]
- public string Get(int id)
- {
- try
- {
- var rune = await dataManager
- .GetItemsByName(name, 0, await dataManager.GetNbItems());
- RuneDto result = champion.First().toDTO();
- return Ok(result);
- }
- catch (Exeption e)
- {
+ }
+ catch (Exception e)
+ {
- new HttpException(400, 'Cannot get rune :' + e.message);
- }
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+ }
+ }*/
- }
+ /* // GET api//5
+ [HttpGet("{id}")]
+ public string Get(int id)
+ {
+ try
+ {
+ var rune = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ RuneDto result = champion.First().toDTO();
+ return Ok(result);
+ }
+ catch (Exeption e)
+ {
- // POST api/
- [HttpPost]
- public void Post([FromBody] string value)
- {
- try
- {
- await dataManager.AddItem(value.toModel());
- return Ok();
- }
- catch ()
- {
- new HttpException(400, 'Cannot create rune')
- }
+ new HttpException(400, 'Cannot get rune :' + e.message);
+ }
- }
+ }*/
+
+ // POST api/
+
// PUT api//5
[HttpPut("{id}")]
@@ -127,6 +184,6 @@ namespace API_LoL_Project.Controllers
[HttpDelete("{id}")]
public void Delete(int id)
{
- }*/
+ }
}
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs
index 76a0d96..271d180 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs
@@ -9,7 +9,7 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class RunePageController : ControllerBase
{
-/* // GET: api/
+ /* // GET: api/
[HttpGet]
public async Task>> Get([FromQuery] Request.PageRequest request)
{
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs
index fa3ddfd..9f41870 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs
@@ -1,4 +1,6 @@
-using Microsoft.AspNetCore.Mvc;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
+using Model;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -8,13 +10,21 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class SkinController : ControllerBase
{
- /* // GET: api/
+ /* public ISkinsManager dataManager;
+ private readonly ILogger _logger;
+ public SkinController(IDataManager dataManager, ILogger logger)
+ {
+ this.dataManager = dataManager.SkinsMgr;
+ this._logger = logger;
+ }
+
+ // GET: api/
[HttpGet]
public async Task>> Get([FromQuery] Request.PageRequest request)
{
try
{
- var totalcount = await runesManager.GetNbItems();
+ var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
@@ -23,7 +33,7 @@ namespace API_LoL_Project.Controllers
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
- var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
+ var runes = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/WeatherForecastController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/WeatherForecastController.cs
deleted file mode 100644
index c27a8af..0000000
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/WeatherForecastController.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-
-namespace API_LoL_Project.Controllers
-{
- [ApiController]
- [Route("[controller]")]
- public class WeatherForecastController : ControllerBase
- {
- private static readonly string[] Summaries = new[]
- {
- "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
- };
-
- private readonly ILogger _logger;
-
- public WeatherForecastController(ILogger logger)
- {
- _logger = logger;
- }
-
- [HttpGet(Name = "GetWeatherForecast")]
- public IEnumerable Get()
- {
- return Enumerable.Range(1, 5).Select(index => new WeatherForecast
- {
- Date = DateTime.Now.AddDays(index),
- TemperatureC = Random.Shared.Next(-20, 55),
- Summary = Summaries[Random.Shared.Next(Summaries.Length)]
- })
- .ToArray();
- }
- }
-}
\ No newline at end of file
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/ChampionsController.cs
new file mode 100644
index 0000000..13fd762
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/ChampionsController.cs
@@ -0,0 +1,339 @@
+using API_LoL_Project.Controllers.Response;
+using API_LoL_Project.Middleware;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using StubLib;
+using System.Collections.Generic;
+using System.Text.Json;
+using System.Xml.Linq;
+using ApiMappeur;
+
+namespace API_LoL_Project.Controllers.version1
+{
+ [Route("api/v{version:apiVersion}/[controller]")]
+ [ApiVersion("1.0")]
+ [ApiController]
+ public class ChampionsController : ControllerBase
+ {
+ public IChampionsManager dataManager;
+ private readonly ILogger _logger;
+ public ChampionsController(IDataManager dataManager, ILogger logger)
+ {
+ this.dataManager = dataManager.ChampionsMgr;
+ _logger = logger;
+ }
+
+ // GET: api//getAllChampions
+ [HttpGet]
+ public async Task>> Get([FromQuery] Request.PageRequest request)
+ {
+ try
+ {
+ var totalcount = await dataManager.GetNbItems();
+ if (request.count * request.index >= totalcount)
+ {
+ _logger.LogError("To many object is asked the max is {totalcount} but the request is superior of ", totalcount);
+ return BadRequest("To many object is asked the max is : " + totalcount);
+ }
+
+ _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); ;
+ var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending);
+ IEnumerable res = champions.Select(c => c.ToDTO());
+ if (res.Count() <= 0 || res == null)
+ {
+ _logger.LogError("No champions found the total count is {totalcount} ", totalcount);
+ return BadRequest("No champions found : totalcount is : " + totalcount);
+ }
+
+ var respList = res.Select(r => new LolResponse
+ (
+ r,
+ new List
+ {
+ EndPointLink.To($"/api1111111111/[controller]/{r.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Get)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
+ }
+ ));
+
+ var pageResponse = new PageResponse(respList, request.index, request.count, totalcount);
+
+ return Ok(pageResponse);
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+
+ }
+ }
+
+
+ /*// GET api//5
+ [HttpGet("{id}")]
+ public async Task>> GetChampionsById(int name)
+ {
+ try
+ {
+
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ IEnumerable res = champion.Select(c => c.toFullDTO());
+
+ if (res == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ return Ok(res);
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+
+ }
+ }*/
+
+ // GET: api//LargeImage
+ [HttpGet("image/{name}")]
+ public async Task> GetChampionsImage(string name)
+ {
+ try
+ {
+ if (name == null || name == "")
+ {
+ var message = string.Format("Can not get champions image without the name (is empty)");
+ _logger.LogWarning(message); ;
+ return BadRequest(message);
+ }
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/
+ ChampionFullDTO res = champion.First().toFullDTO();//.First
+
+ if (res == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+
+ return Ok(res.LargeImage);
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+
+ }
+ }
+
+
+ // GET api//name
+ [HttpGet("{name}")]
+ public async Task>> GetChampionsByName(string name)
+ {
+ if (name == null || name == "")
+ {
+ var message = string.Format("Can not get champions without the name (is empty)");
+ _logger.LogWarning(message); ;
+ return BadRequest(message);
+ }
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ try
+ {
+ var totalcount = await dataManager.GetNbItemsByName(name);
+ if (totalcount <= 0)
+ {
+ _logger.LogError("No chamions found with this name {name} in the dataContext", name); ;
+ return BadRequest("No chamions found with this name: " + name + "in the dataContext");
+ }
+
+ var champion = await dataManager.GetItemsByName(name, 0, totalcount);
+ /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/
+ if (champion.Count() <= 0 || champion == null)
+ {
+ _logger.LogError($"No chamions found with {name} executing {nameof(GetChampionsByName)}"); ;
+ return NotFound("No chamions found with" + name);
+ }
+ ChampionFullDTO res = champion.First().toFullDTO();//.First
+
+
+ var links = new List
+ {
+ EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
+ };
+
+ var response = new LolResponse(res, links);
+ return Ok(response);
+
+ }
+ catch (Exception e)
+ {
+
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest("Somthing goes wrong caching the Champions controller : " + e.Message);
+
+ }
+ }
+
+
+ // POST api/ Post([FromBody] ChampionFullDTO value)
+ {
+ try
+ {
+ // generic validation
+ var newChampion = value.ToModel();
+ await dataManager.AddItem(newChampion);
+ // can we check with a method
+ //var savedChampions = await dataManager.GetItemsByName(newChampion.name, 0, await dataManager.GetNbItems())
+ /*if (savedChampions.Count() >= 0 || res == null)
+ {
+ _logger.LogWarning("No chamions found ");
+ return BadRequest("No chamions found ");
+ }*/
+ _logger.LogInformation("Sucessfully saved Champions : " + newChampion.Name);
+
+ return CreatedAtAction(nameof(Get), newChampion);
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+
+ }
+
+ }
+ // should change for id cause model implementation use filteringbyName to getItemByNAme and it use substring
+ // PUT api//5
+ [HttpPut("{name}")]
+ public async Task Put(string name, [FromBody] ChampionDTO value)
+ {
+ try
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name);
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champion == null)
+ {
+ _logger.LogError("No chamions found with {name} in the dataBase", name); ;
+ return NotFound();
+ }
+
+ await dataManager.UpdateItem(champion.First(), value.ToModel());
+ return Ok();
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+ }
+ }
+
+ // DELETE api//5
+ [HttpDelete("{name}")]
+ public async Task Delete(string name)
+ {
+ try
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Delete), name);
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+
+ if (champion != null) await dataManager.DeleteItem(champion.First());
+ else
+ {
+ _logger.LogError($"No chamions found with {name} cannot delete"); ;
+ return NotFound($"No chamions found with {name} cannot delete");
+ }
+ return Ok();
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+ }
+
+ }
+
+ /* [HttpGet]
+ public async Task NbChampions()
+ {
+ var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
+ IEnumerable res = champions.Select(c => c.toDTO());
+ return Ok(res);
+
+ }*/
+
+ [HttpGet("/{name}/skins")]
+ public async Task> GetChampionsSkins(string name)
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkins), name);
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champions == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ //skinsDTO
+ IEnumerable res = champions.First().Skins.Select(c => c.ToDto());
+ if (res == null)
+ {
+ _logger.LogWarning("No skins found for {name}", name); ;
+ return NotFound();
+ }
+ return Ok(res);
+ }
+
+ /* [HttpGet("/{name}/skills")]
+ public async Task> GetChampionsSkills(string name)
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name);
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champions == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ //skinsDTO
+ IEnumerable res = champions.First().Skills.to;
+ if (res == null)
+ {
+ _logger.LogWarning("No skins found for {name}", name); ;
+ return NotFound();
+ }
+
+ return Ok(res);
+ }*/
+
+ [HttpPost("/{name}/skills")]
+ public async Task>> AddChampionsSkills(string name)
+ {
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ //SkillDTO
+ IEnumerable res = champions.First().Skills;
+
+ return Ok(res);
+ }
+
+ // degradation du modèle cleitn ell est dédié au cliens
+ [HttpGet("/count")]
+ public async Task> NbChampions()
+ {
+ var nbChampions = await dataManager.GetNbItems();
+ return Ok(nbChampions);
+ }
+
+ }
+}
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs
new file mode 100644
index 0000000..58fa3c9
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs
@@ -0,0 +1,399 @@
+using API_LoL_Project.Controllers.Response;
+using API_LoL_Project.Middleware;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using StubLib;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
+using System.Xml.Linq;
+using ApiMappeur;
+
+
+namespace API_LoL_Project.Controllers.version2
+{
+ [Route("api/v{version:apiVersion}/[controller]")]
+ [ApiVersion("2.0")]
+ [ApiController]
+ public class ChampionsController : ControllerBase
+ {
+ public IChampionsManager dataManager;
+ private readonly ILogger _logger;
+
+ public ChampionsController(IDataManager dataManager, ILogger logger)
+ {
+ this.dataManager = dataManager.ChampionsMgr;
+ _logger = logger;
+ }
+
+
+
+ // GET: api/champions/
+ [HttpGet]
+ public async Task>> Get([FromQuery] Request.PageRequest request)
+ {
+ try
+ {
+ var totalcount = await dataManager.GetNbItems();
+ if (request.count * request.index >= totalcount)
+ {
+ _logger.LogError("To many object is asked the max is {totalcount} but the request is superior of ", totalcount);
+ return BadRequest("To many object is asked the max is : " + totalcount);
+ }
+
+ _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); ;
+ var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending);
+ IEnumerable res = champions.Select(c => c.ToDTO());
+ if (res.Count() <= 0 || res == null)
+ {
+ _logger.LogError("No champions found the total count is {totalcount} ", totalcount);
+ return BadRequest("No champions found : totalcount is : " + totalcount);
+ }
+
+ var respList = res.Select(r => new LolResponse
+ (
+ r,
+ new List
+ {
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
+ }
+ ));
+
+ var pageResponse = new PageResponse(respList, request.index, request.count, totalcount);
+
+ return Ok(pageResponse);
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+
+ }
+ }
+
+
+ /*// GET api//5
+ [HttpGet("{id}")]
+ public async Task>> GetChampionsById(int name)
+ {
+ try
+ {
+
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ IEnumerable res = champion.Select(c => c.toFullDTO());
+
+ if (res == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ return Ok(res);
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+
+ }
+ }*/
+
+ // GET: api/champions/image
+ [HttpGet("image/{name}")]
+ public async Task> GetChampionsImage(string name)
+ {
+ try
+ {
+ if (name == null || name == "")
+ {
+ var message = string.Format("Can not get champions image without the name (is empty)");
+ _logger.LogWarning(message + nameof(ChampionsController)); ;
+ return BadRequest(message);
+ }
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/
+ ChampionFullDTO res = champion.First().toFullDTO();//.First
+
+ if (res == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+
+ return Ok(res.LargeImage);
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+
+ }
+ }
+
+
+ // GET api/champions/name
+ [HttpGet("{name}")]
+ public async Task>> GetChampionsByName(string name)
+ {
+ if (name == null || name == "")
+ {
+ var message = string.Format("Can not get champions without the name (is empty)");
+ _logger.LogWarning(message); ;
+ return BadRequest(message);
+ }
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ try
+ {
+ var totalcount = await dataManager.GetNbItemsByName(name);
+ if (totalcount <= 0)
+ {
+ _logger.LogError("No chamions found with this name {name} in the dataContext", name); ;
+ return BadRequest("No chamions found with this name: " + name + "in the dataContext");
+ }
+ var champion = await dataManager.GetItemsByName(name, 0, totalcount);
+ _logger.LogError($"========================= {champion} ================================================"); ;
+
+ if (champion.Count() <= 0 || champion == null)
+ {
+ _logger.LogError($"No chamions found with {name} executing {nameof(GetChampionsByName)}"); ;
+ return NotFound("No chamions found with" + name);
+ }
+ IEnumerable res = champion.Select(c => c.toFullDTO());
+ /*ChampionFullDTO res = champion.First().toFullDTO();//.First*/
+ var respList = res.Select(r => new LolResponse
+ (
+ r,
+ new List
+ {
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
+ }
+ ));
+
+ return Ok(respList);
+
+ }
+ catch (Exception e)
+ {
+
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest("Somthing goes wrong caching the Champions controller : " + e.Message);
+
+ }
+ }
+
+
+ // POST api/champions/names
+ // it should be better if we get a Champions From the Model but cause the Client (MAUI one) Send Champion there is no interest to be a championDTo
+ /* [HttpPost]
+ public async Task Post([FromBody] Champion value)
+ {
+ try
+ {
+ if (value == null)
+ {
+ var message = string.Format("Can not get champions image without the name (is empty)");
+ _logger.LogWarning(message); ;
+ return BadRequest(message);
+ }
+ // generic validation check if all field is good
+ await dataManager.AddItem(value);
+ // can we check with a method
+ //var savedChampions = await dataManager.GetItemsByName(newChampion.name, 0, await dataManager.GetNbItems())
+ *//*if (savedChampions.Count() >= 0 || res == null)
+ {
+ _logger.LogWarning("No chamions found ");
+ return BadRequest("No chamions found ");
+ }*//*
+ _logger.LogInformation("Sucessfully saved Champions : " + value.Name);
+
+ return CreatedAtAction(nameof(Get), value.ToDTO());
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+
+ }
+
+ }
+ */
+
+ [HttpPost]
+ public async Task Post([FromBody] ChampionFullDTO value)
+ {
+ try
+ {
+ if (value == null)
+ {
+ var message = string.Format("Can not get champions image without the name (is empty)");
+ _logger.LogWarning(message); ;
+ return BadRequest(message);
+ }
+ // generic validation check if all field is good
+ var newChampion = value.ToModel();
+ await dataManager.AddItem(newChampion);
+ // can we check with a method
+ var savedChampions = await dataManager.GetItemsByName(newChampion.Name, 0, await dataManager.GetNbItems());
+ if (savedChampions.Count() <= 0 || savedChampions == null)
+ {
+ _logger.LogWarning("No chamions found ");
+ return BadRequest("No chamions found ");
+ }
+ _logger.LogInformation("Sucessfully saved Champions : " + newChampion.Name);
+
+ return CreatedAtAction(nameof(Get), newChampion.ToDTO());
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+
+ }
+
+ }
+
+
+ // should change for id cause model implementation use filteringbyName to getItemByNAme and it use substring
+ // PUT api//5
+ [HttpPut("{name}")]
+ public async Task Put(string name, [FromBody] ChampionDTO value)
+ {
+ try
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name);
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champion == null)
+ {
+ _logger.LogError("No chamions found with {name} in the dataBase", name); ;
+ return NotFound();
+ }
+
+ await dataManager.UpdateItem(champion.First(), value.ToModel());
+ return Ok();
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+ }
+ }
+
+ // DELETE api//5
+ [HttpDelete("{name}")]
+ public async Task Delete(string name)
+ {
+ try
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Delete), name);
+
+ if (string.IsNullOrEmpty(name))
+ {
+ var message = string.Format("Can not delelte champions without the name (is empty)");
+ _logger.LogWarning(message + nameof(ChampionsController)); ;
+ return BadRequest(message);
+ }
+
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+
+ if (champion != null) await dataManager.DeleteItem(champion.First());
+ else
+ {
+ _logger.LogError($"No chamions found with {name} cannot delete"); ;
+ return NotFound($"No chamions found with {name} cannot delete");
+ }
+ return Ok();
+ }
+ catch (Exception e)
+ {
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+ }
+
+ }
+
+ /* [HttpGet]
+ public async Task NbChampions()
+ {
+ var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
+ IEnumerable res = champions.Select(c => c.toDTO());
+ return Ok(res);
+
+ }*/
+
+ [HttpGet("/{name}/skins")]
+ public async Task> GetChampionsSkins(string name)
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkins), name);
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champions == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ //skinsDTO
+ IEnumerable res = champions.First().Skins.Select(c => c.ToDto());
+ if (res == null)
+ {
+ _logger.LogWarning("No skins found for {name}", name); ;
+ return NotFound();
+ }
+ return Ok(res);
+ }
+
+ /* [HttpGet("/{name}/skills")]
+ public async Task> GetChampionsSkills(string name)
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name);
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champions == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ //skinsDTO
+ IEnumerable res = champions.First().Skills.to;
+ if (res == null)
+ {
+ _logger.LogWarning("No skins found for {name}", name); ;
+ return NotFound();
+ }
+
+ return Ok(res);
+ }*/
+
+ [HttpPost("/{name}/skills")]
+ public async Task>> AddChampionsSkills(string name)
+ {
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ //SkillDTO
+ IEnumerable res = champions.First().Skills;
+
+ return Ok(res);
+ }
+
+ // degradation du modèle cleitn ell est dédié au cliens
+ [HttpGet("/count")]
+ public async Task> NbChampions()
+ {
+ var nbChampions = await dataManager.GetNbItems();
+ return Ok(nbChampions);
+ }
+
+
+
+
+ }
+}
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm
index ab9f051..d13c8ac 100644
Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm differ
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal
index cc80bcb..4e1e31d 100644
Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal differ
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/JsonConverter/ReadOnlyDictionaryConverter.cs b/EntityFramework_LoL/Sources/API_LoL_Project/JsonConverter/ReadOnlyDictionaryConverter.cs
new file mode 100644
index 0000000..035f8ae
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/JsonConverter/ReadOnlyDictionaryConverter.cs
@@ -0,0 +1,20 @@
+using System.Collections.ObjectModel;
+using System.Text.Json.Serialization;
+using System.Text.Json;
+
+namespace API_LoL_Project.JsonConverter
+{
+ public class ReadOnlyDictionaryConverter : JsonConverter>
+ {
+ public override ReadOnlyDictionary Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ Dictionary dictionary = JsonSerializer.Deserialize>(ref reader, options);
+ return new ReadOnlyDictionary(dictionary);
+ }
+
+ public override void Write(Utf8JsonWriter writer, ReadOnlyDictionary value, JsonSerializerOptions options)
+ {
+ JsonSerializer.Serialize(writer, value.ToDictionary(kv => kv.Key, kv => kv.Value), options);
+ }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs b/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs
new file mode 100644
index 0000000..14c6270
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs
@@ -0,0 +1,65 @@
+using Microsoft.AspNetCore.Mvc.ApiExplorer;
+using Microsoft.Extensions.Options;
+using Microsoft.OpenApi.Models;
+using Swashbuckle.AspNetCore.SwaggerGen;
+
+namespace API_LoL_Project
+{
+ public class LolSwaggerOptions : IConfigureNamedOptions
+ {
+ private readonly IApiVersionDescriptionProvider _provider;
+
+ public LolSwaggerOptions(
+ 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;
+ }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs
index 15f2889..c510a87 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs
@@ -6,20 +6,6 @@ namespace API_LoL_Project.Mapper
{
public static class ChampionMapper {
- public static ChampionDTO ToDTO(this Champion item)
- {
- if (item == null)
- {
- var message = string.Format("Champion with name = {} nhhoddt found", item.Name);
- /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
- */
- }
- return new ChampionDTO() {
- Name = item.Name,
- Bio = item.Bio
- };
- }
-
public static ChampionEntity ToEntity(this Champion item)
{
return new()
@@ -31,27 +17,7 @@ namespace API_LoL_Project.Mapper
Image = new() { Base64 = item.Image.Base64 },
};
}
- public static ChampionFullDTO toFullDTO(this Champion item)
- {
- if (item == null)
- {
- var message = string.Format("Champion with name = {} nhhoddt found", item.Name);
- /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
- */
- }
- return new ChampionFullDTO()
- {
- Name = item.Name,
- Bio = item.Bio,
- skills = item.Skills,
- skins = item.Skins,
- LargeImage = item.Image.Base64
-
- };
-
- }
-
-
+
public static Champion ToModel(this ChampionDTO dto)
{
if (dto == null)
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponse.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponse.cs
new file mode 100644
index 0000000..de90660
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponse.cs
@@ -0,0 +1,18 @@
+using API_LoL_Project.Controllers.Response;
+using System.Net;
+
+namespace API_LoL_Project.Middleware
+{
+ public class LolResponse
+ {
+ public T Data { get; set; }
+ public List Links { get; set; } = null;
+
+
+ public LolResponse(T data , List? links)
+ {
+ this.Data = data;
+ this.Links = links;
+ }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs
index 68e54ad..5c3cd07 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs
@@ -1,8 +1,13 @@
using Business;
using Entities;
using Microsoft.EntityFrameworkCore;
+using Microsoft.AspNetCore.Mvc.ApiExplorer;
+using Microsoft.AspNetCore.Mvc.Versioning;
using Model;
using StubLib;
+using API_LoL_Project;
+using API_LoL_Project.JsonConverter;
+
var builder = WebApplication.CreateBuilder(args);
@@ -10,14 +15,33 @@ var connectionString = builder.Configuration.GetConnectionString("LolDatabase");
builder.Services.AddDbContext(options =>
options.UseSqlite(connectionString), ServiceLifetime.Singleton);
-builder.Services.AddControllers();
+builder.Services.AddControllers().AddJsonOptions(options =>
+{
+ options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionaryConverter());
+});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
+builder.Services.AddApiVersioning(opt =>
+{
+ opt.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);
+ opt.AssumeDefaultVersionWhenUnspecified = true;
+ opt.ReportApiVersions = true;
+ opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader());
+});
+builder.Services.ConfigureOptions();
+builder.Services.AddVersionedApiExplorer(setup =>
+{
+ setup.GroupNameFormat = "'v'VVV";
+ setup.SubstituteApiVersionInUrl = true;
+});
+
+
builder.Services.AddSingleton();
//builder.Services.AddSingleton();
var app = builder.Build();
+var apiVersionDescriptionProvider = app.Services.GetRequiredService();
app?.Services?.GetService()?.Database.EnsureCreated();
@@ -25,7 +49,15 @@ app?.Services?.GetService()?.Database.EnsureCreated();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
- app.UseSwaggerUI();
+ /* app.UseSwaggerUI();*/
+ app.UseSwaggerUI(options =>
+ {
+ foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
+ {
+ options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
+ description.GroupName.ToUpperInvariant());
+ }
+ });
}
app.UseHttpsRedirection();
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/WeatherForecast.cs b/EntityFramework_LoL/Sources/API_LoL_Project/WeatherForecast.cs
deleted file mode 100644
index 350bb53..0000000
--- a/EntityFramework_LoL/Sources/API_LoL_Project/WeatherForecast.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace API_LoL_Project
-{
- public class WeatherForecast
- {
- public DateTime Date { get; set; }
-
- public int TemperatureC { get; set; }
-
- public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
-
- public string? Summary { get; set; }
- }
-}
\ No newline at end of file
diff --git a/EntityFramework_LoL/Sources/ApiLib/ApiLib.csproj b/EntityFramework_LoL/Sources/ApiLib/ApiLib.csproj
new file mode 100644
index 0000000..64310df
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiLib/ApiLib.csproj
@@ -0,0 +1,15 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/EntityFramework_LoL/Sources/ApiMappeur/ApiMappeur.csproj b/EntityFramework_LoL/Sources/ApiMappeur/ApiMappeur.csproj
new file mode 100644
index 0000000..c322be1
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiMappeur/ApiMappeur.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs
new file mode 100644
index 0000000..83481f1
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs
@@ -0,0 +1,103 @@
+using API_LoL_Project.Mapper;
+using ApiMappeur;
+using DTO;
+using Entities;
+using Model;
+
+namespace ApiMappeur
+{
+ public static class ChampionMapper
+ {
+
+ public static ChampionDTO ToDTO(this Champion item)
+ {
+ /*if (item == null)
+ {
+ var message = string.Format("Champion cannot be empty");
+ *//*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
+ *//*
+ throw new Exception(message);
+ }*/
+ return new ChampionDTO()
+ {
+ Icon = item.Icon,
+ Name = item.Name,
+ Bio = item.Bio,
+ Class = item.Class
+ };
+ }
+
+ public static ChampionEntity ToEntity(this Champion item)
+ {
+ return new()
+ {
+ Name = item.Name,
+ Bio = item.Bio,
+ Icon = item.Icon,
+ Class = item.Class,
+ Image = new() { Base64 = item.Image.Base64 },
+ };
+ }
+ public static ChampionFullDTO toFullDTO(this Champion item)
+ {
+ if (item == null)
+ {
+ var message = string.Format("Champion with name = {} not found", item.Name);
+ /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
+ */
+ throw new Exception(message);
+
+ }
+ return new ChampionFullDTO()
+ {
+ Name = item.Name,
+ Bio = item.Bio,
+ Skills = item.Skills,
+ Class = item.Class,
+ Skins = item.Skins.Select(i => i.ToDto()),
+ LargeImage = item.Image.ToDTO()
+
+ };
+
+ }
+
+ public static Champion ToModel(this ChampionFullDTO dto)
+ {
+ if (dto == null)
+ {
+ var message = string.Format("Champion cannot be empty");
+ /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
+ */
+ throw new Exception(message);
+
+ }
+ return new Champion(dto.Name, dto.Class, dto.Icon, dto.LargeImage.base64, dto.Bio);
+
+
+ ;
+ }
+ public static Champion ToModel(this ChampionDTO dto)
+ {
+ if (dto == null)
+ {
+ var message = string.Format("Champion cannot be empty");
+ /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
+ */
+ throw new Exception(message);
+
+ }
+ return new Champion(dto.Name, dto.Class, dto.Icon)
+ {
+ Bio = dto.Bio
+ };
+ }
+
+ public static Champion ToModel(this ChampionEntity entity)
+ {
+ return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio);
+ }
+
+
+
+ }
+}
diff --git a/EntityFramework_LoL/Sources/ApiMappeur/ImageMappeur.cs b/EntityFramework_LoL/Sources/ApiMappeur/ImageMappeur.cs
new file mode 100644
index 0000000..1e5d432
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiMappeur/ImageMappeur.cs
@@ -0,0 +1,23 @@
+using DTO;
+using Model;
+
+namespace ApiMappeur
+{
+ public static class ImageMappeur
+ {
+ public static ImageDTO ToDTO(this LargeImage item)
+ {
+ if (item == null)
+ {
+ var message = string.Format("Image cannot be empty");
+ /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
+ */
+ }
+ return new ImageDTO()
+ {
+ base64 = item.Base64
+ };
+ }
+
+ }
+}
diff --git a/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs
new file mode 100644
index 0000000..63fb9c5
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs
@@ -0,0 +1,31 @@
+ using DTO;
+ using Model;
+
+ namespace API_LoL_Project.Mapper
+ {
+ public static class RuneMapper
+ {
+ public static RuneDTO ToDTO(this Rune item)
+ {
+
+ return new RuneDTO()
+ {
+ Name = item.Name,
+ Family = item.Family,
+ };
+ }
+
+ public static Rune ToModel(this RuneDTO dto)
+ {
+ /*if (dto == null)
+ {
+ *//* var message = string.Format("Champion with name = {} not found", dto.Name);
+ throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//*
+ }*/
+ return new Rune(dto.Name, dto.Family);
+ }
+ }
+ }
+
+
+
diff --git a/EntityFramework_LoL/Sources/ApiMappeur/RunePageMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/RunePageMapper.cs
new file mode 100644
index 0000000..9d334a7
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiMappeur/RunePageMapper.cs
@@ -0,0 +1,10 @@
+using Entities;
+using Model;
+
+namespace ApiMappeur
+{
+ public static class RunePageMapper
+ {
+
+ }
+}
diff --git a/EntityFramework_LoL/Sources/ApiMappeur/SkinMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/SkinMapper.cs
new file mode 100644
index 0000000..a325e26
--- /dev/null
+++ b/EntityFramework_LoL/Sources/ApiMappeur/SkinMapper.cs
@@ -0,0 +1,30 @@
+using DTO;
+using Entities;
+using Model;
+
+namespace ApiMappeur
+{
+ public static class SkinMapper
+ {
+
+
+ public static Skin ToModel(this SkinEntity entity)
+ {
+ throw new NotImplementedException();
+
+ }
+ public static SkinDto ToDto(this Skin item)
+ {
+ return new SkinDto()
+ {
+ Name = item.Name,
+ Description = item.Description,
+ Icon = item.Icon,
+ Price = item.Price
+ };
+
+ }
+
+ }
+}
+
diff --git a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs
index 0f77a48..a1766a2 100644
--- a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs
+++ b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs
@@ -1,24 +1,74 @@
using Model;
-using System.Buffers.Text;
-
-namespace DTO
-{
- public class ChampionDTO
- {
- public string Name { get; set; }
- public string Bio { get; set; }
- /*public string Icon { get; set; }
- */
- }
- public class ChampionFullDTO
- {
- public string Name { get; set; }
- public string Bio { get; set; }
- public string Characteristics { get; set; }
- public string LargeImage { get; set; }
-
- public IEnumerable skins { get; set; }
- public IEnumerable skills { get; set; }
-
- }
+using Shared;
+using System.Collections.ObjectModel;
+using System.ComponentModel.DataAnnotations;
+using System.Text.Json.Serialization;
+using static System.Net.Mime.MediaTypeNames;
+
+namespace DTO
+{
+ public class ChampionDTO
+ {
+ public string Name { get; set; }
+ public string Bio { get; set; }
+ public string Icon { get; set; }
+ public ChampionClass Class { get; set; }
+ }
+
+
+ /*public class ChampionFullDTO
+ {
+ *//*[Required(ErrorMessage = "Name is required")]
+ [StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*//*
+ [JsonPropertyName("name")]
+ public string Name { get; set; }
+ [JsonPropertyName("bio")]
+ public string Bio { get; set; }
+
+ public ChampionClass Class {get; set;}
+ public string Icon {get; set;}
+
+ public ReadOnlyDictionary Characteristics { get; set; }
+ public ImageDTO LargeImage { get; set; }
+
+ public IEnumerable skins { get; set; }
+ public IEnumerable skills { get; set; }
+
+ public ChampionFullDTO()
+ {
+ Characteristics = new ReadOnlyDictionary(new Dictionary());
+ }
+
+
+ }
+*/
+ public class ChampionFullDTO
+ {
+
+ [JsonPropertyName("characteristics")]
+ public ReadOnlyDictionary Characteristics { get; set; }
+
+ [JsonPropertyName("name")]
+ public string Name { get; set; }
+
+ [JsonPropertyName("bio")]
+ public string Bio { get; set; }
+
+ [JsonPropertyName("class")]
+ public ChampionClass Class { get; set; }
+
+ [JsonPropertyName("icon")]
+ public string Icon { get; set; }
+
+
+ [JsonPropertyName("largeImage")]
+ public ImageDTO LargeImage { get; set; }
+
+ [JsonPropertyName("skins")]
+ public IEnumerable Skins { get; set; }
+
+ [JsonPropertyName("skills")]
+ public IEnumerable Skills { get; set; }
+ }
+
}
\ No newline at end of file
diff --git a/EntityFramework_LoL/Sources/DTO/ImageDTO.cs b/EntityFramework_LoL/Sources/DTO/ImageDTO.cs
new file mode 100644
index 0000000..3b5cec1
--- /dev/null
+++ b/EntityFramework_LoL/Sources/DTO/ImageDTO.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class ImageDTO
+ {
+ public string base64 { get; set; }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs
index f0a5d4f..64b8989 100644
--- a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs
+++ b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs
@@ -14,9 +14,9 @@ namespace DTO
public string Description { get; set; }
- public RuneFamily Family { get; set; }
+ public RuneFamily Family { get; set; }
- public string Icon { get; set; }
+ public string Icon { get; set; }
public LargeImage Image { get; set; }
}
diff --git a/EntityFramework_LoL/Sources/DTO/SkillDto.cs b/EntityFramework_LoL/Sources/DTO/SkillDto.cs
new file mode 100644
index 0000000..2b7f006
--- /dev/null
+++ b/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/EntityFramework_LoL/Sources/DTO/SkinDto.cs b/EntityFramework_LoL/Sources/DTO/SkinDto.cs
new file mode 100644
index 0000000..2c3962b
--- /dev/null
+++ b/EntityFramework_LoL/Sources/DTO/SkinDto.cs
@@ -0,0 +1,17 @@
+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 float Price { get; set; }
+
+ }
+}
diff --git a/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln
index 0676ee3..c909e99 100644
--- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln
+++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln
@@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_LoL_Project", "API_LoL_Project\API_LoL_Project.csproj", "{4EDC93E0-35B8-4EF1-9318-24F7A606BA97}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{7F6A519E-98F8-429E-B34F-9B0D20075CFB}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Entity Framework", "Entity Framework", "{BC2FFCA4-3801-433F-A83E-B55345F3B31E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}"
@@ -26,13 +24,18 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}"
-<<<<<<< HEAD
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityMappers", "EntityMappers\EntityMappers.csproj", "{3A70A719-4F42-4CC3-846A-53437F3B4CC5}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityMappers", "EntityMappers\EntityMappers.csproj", "{3A70A719-4F42-4CC3-846A-53437F3B4CC5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4008CA21-360B-4C39-8AC3-6E5B02552E22}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestEF", "TestEF\TestEF.csproj", "{059B4A61-E9D5-4C00-8178-C8714D781FBC}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEF", "TestEF\TestEF.csproj", "{059B4A61-E9D5-4C00-8178-C8714D781FBC}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiLib", "ApiLib\ApiLib.csproj", "{3D3CBA61-0C8E-4B22-9CAA-66845E1D6C96}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiMappeur", "ApiMappeur\ApiMappeur.csproj", "{709010E2-F36C-4FD9-91D3-D3806EE28B88}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{CA27B501-E120-4551-ABAE-BCE1B85B7455}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -60,10 +63,6 @@ Global
{4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EDC93E0-35B8-4EF1-9318-24F7A606BA97}.Release|Any CPU.Build.0 = Release|Any CPU
- {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.Build.0 = Release|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -84,6 +83,18 @@ Global
{059B4A61-E9D5-4C00-8178-C8714D781FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{059B4A61-E9D5-4C00-8178-C8714D781FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{059B4A61-E9D5-4C00-8178-C8714D781FBC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3D3CBA61-0C8E-4B22-9CAA-66845E1D6C96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3D3CBA61-0C8E-4B22-9CAA-66845E1D6C96}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3D3CBA61-0C8E-4B22-9CAA-66845E1D6C96}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3D3CBA61-0C8E-4B22-9CAA-66845E1D6C96}.Release|Any CPU.Build.0 = Release|Any CPU
+ {709010E2-F36C-4FD9-91D3-D3806EE28B88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {709010E2-F36C-4FD9-91D3-D3806EE28B88}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {709010E2-F36C-4FD9-91D3-D3806EE28B88}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {709010E2-F36C-4FD9-91D3-D3806EE28B88}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CA27B501-E120-4551-ABAE-BCE1B85B7455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CA27B501-E120-4551-ABAE-BCE1B85B7455}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CA27B501-E120-4551-ABAE-BCE1B85B7455}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CA27B501-E120-4551-ABAE-BCE1B85B7455}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs b/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs
index 51f8dd8..6a987ce 100644
--- a/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs
+++ b/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs
@@ -1,7 +1,12 @@
using API_LoL_Project.Controllers;
+using API_LoL_Project.Controllers.Request;
+using API_LoL_Project.Controllers.Response;
+using API_LoL_Project.Controllers.version2;
using DTO;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
using Model;
using StubLib;
using System.Net;
@@ -11,38 +16,183 @@ namespace Test_Api
[TestClass]
public class ChampionControllerTest
{
- public readonly ChampionsController championCtrl;
+ public ChampionsController championCtrl;
+ private readonly ILogger logger = new NullLogger();
public readonly IDataManager stubMgr;
-
- public ChampionControllerTest(ILogger logger)
+ public ChampionControllerTest()
{
var stubMgr = new StubData();
championCtrl = new ChampionsController(stubMgr, logger);
}
-
+/*
[TestMethod]
public async Task TestGetChampions()
{
-/* var getResult = await championCtrl.Get();
- Console.WriteLine(getResult);
- var objectRes = getResult as OkObjectResult;
+
+
+ var request = new PageRequest
+ {
+ index = 0,
+ count = 10,
+ orderingPropertyName = "Name",
+ descending = false
+ };
+
+ var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
+
+ // Act
+
+ var getResult = await championCtrl.Get(request);
+
+
+
+ // Assert
+ Assert.IsInstanceOfType(getResult, typeof(OkObjectResult));
+
+ var objectRes = getResult.Result as OkObjectResult;
Assert.AreEqual(200, objectRes.StatusCode);
Assert.IsNotNull(objectRes);
-
+
var champions = objectRes?.Value as IEnumerable;
- Assert.IsNotNull(champions);*/
+ Assert.IsNotNull(champions);
-/*
- Assert.AreEqual(champions.Count(), await stubMgr.ChampionsMgr.GetNbItems());*/
+ Assert.IsInstanceOfType(objectRes.Value, typeof(PageResponse));
+ var pageResponse = objectRes.Value as PageResponse;
+ Assert.AreEqual(totalcountTest, pageResponse.TotalCount);
+ Assert.AreEqual(totalcountTest, pageResponse.Data.Count());
+
+
+ *//* Assert.AreEqual(1, pageResponse.Data[.Data.Id);
+ *//* Assert.AreEqual("Champion1", pageResponse.Items[0].Data.Name);
+ *//* Assert.AreEqual(2, pageResponse.Items[1].Data.Id);
+ *//* Assert.AreEqual("Champion2", pageResponse.Items[1].Data.Name);
+ */
+ /*
+ Assert.AreEqual(champions.Count(), await stubMgr.ChampionsMgr.GetNbItems());*//*
}
+ [TestMethod]
+ public async Task TestGetChampions_When_Count_Index_Too_High()
+ {
+
+ var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
+
+
+ var request = new PageRequest
+ {
+ index = 999,
+ count = 9,
+ orderingPropertyName = "Name",
+ descending = false
+ };
+
+
+ // Act
+
+ var getResult = await championCtrl.Get(request);
+
+ // Assert
+ var badRequestResult = getResult.Result as BadRequestObjectResult;
+ Assert.IsNotNull(badRequestResult);
+ Assert.AreEqual("To many object is asked the max is : {totalcountTest}", badRequestResult.Value);
+ }
+
+
+ [TestMethod]
+ public async Task TestGetBadRequest_WhenNoChampionsFound()
+ {
+
+ ///var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
+ // need to be empty
+
+ var request = new PageRequest
+ {
+ index = 0,
+ count = 10,
+ orderingPropertyName = "Name",
+ descending = false
+ };
+
+
+ // Act
+
+ var getResult = await championCtrl.Get(request);
+ Console.WriteLine(getResult);
+ // Assert
+ var badRequestResult = getResult.Result as BadRequestObjectResult;
+ Assert.IsNotNull(badRequestResult);
+ Assert.AreEqual("No chamions found : totalcount is : 0", badRequestResult.Value);
+ }
+
+*/
+
+
+ /*
+ [TestMethod]
+ public async Task TestPostChampions()
+ {
+
+ var getResult = await championCtrl.Get();
+ Console.WriteLine(getResult);
+ var objectRes = getResult as OkObjectResult;
+
+ Assert.AreEqual(200, objectRes.StatusCode);
+
+ Assert.IsNotNull(objectRes);
+
+ var champions = objectRes?.Value as IEnumerable;
+
+ Assert.IsNotNull(champions);
+
+
+ }
+
+ [TestMethod]
+ public async Task TestUpdateChampions()
+ {
+
+ var getResult = await championCtrl.Get();
+ Console.WriteLine(getResult);
+ var objectRes = getResult as OkObjectResult;
+
+ Assert.AreEqual(200, objectRes.StatusCode);
+
+ Assert.IsNotNull(objectRes);
+
+ var champions = objectRes?.Value as IEnumerable;
+
+ Assert.IsNotNull(champions);
+
+
+ }
+
+ [TestMethod]
+ public async Task TestDeleteChampions()
+ {
+
+ var getResult = await championCtrl.Get();
+ Console.WriteLine(getResult);
+ var objectRes = getResult as OkObjectResult;
+
+ Assert.AreEqual(200, objectRes.StatusCode);
+
+ Assert.IsNotNull(objectRes);
+
+ var champions = objectRes?.Value as IEnumerable;
+
+ Assert.IsNotNull(champions);
+
+
+ }
+
+ */
}
}
\ No newline at end of file
diff --git a/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj b/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj
index e80b67b..66bdcf5 100644
--- a/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj
+++ b/EntityFramework_LoL/Sources/Test_Api/Test_Api.csproj
@@ -17,7 +17,6 @@
-