|
|
@ -9,7 +9,8 @@ using System.Linq;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using ApiMappeur;
|
|
|
|
using ApiMappeur;
|
|
|
|
|
|
|
|
using Shared;
|
|
|
|
|
|
|
|
using Microsoft.OpenApi.Extensions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace API_LoL_Project.Controllers.version2
|
|
|
|
namespace API_LoL_Project.Controllers.version2
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -42,8 +43,9 @@ namespace API_LoL_Project.Controllers.version2
|
|
|
|
return BadRequest("To many object is asked the max is : " + totalcount);
|
|
|
|
return BadRequest("To many object is asked the max is : " + totalcount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); ;
|
|
|
|
_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);
|
|
|
|
|
|
|
|
|
|
|
|
var champions = await dataManager.GetItems(request.index, request.count == 0 ? totalcount : (int)request.count , request.orderingPropertyName, request.descending == null ? false : (bool)request.descending);
|
|
|
|
IEnumerable<ChampionDTO> res = champions.Select(c => c.ToDTO());
|
|
|
|
IEnumerable<ChampionDTO> res = champions.Select(c => c.ToDTO());
|
|
|
|
if (res.Count() <= 0 || res == null)
|
|
|
|
if (res.Count() <= 0 || res == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -158,7 +160,7 @@ namespace API_LoL_Project.Controllers.version2
|
|
|
|
return BadRequest("No chamions found with this name: " + name + "in the dataContext");
|
|
|
|
return BadRequest("No chamions found with this name: " + name + "in the dataContext");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var champion = await dataManager.GetItemsByName(name, 0, totalcount);
|
|
|
|
var champion = await dataManager.GetItemsByName(name, 0, totalcount);
|
|
|
|
_logger.LogError($"========================= {champion} ================================================"); ;
|
|
|
|
_logger.LogInformation($"========================= {champion} ================================================"); ;
|
|
|
|
|
|
|
|
|
|
|
|
if (champion.Count() <= 0 || champion == null)
|
|
|
|
if (champion.Count() <= 0 || champion == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -172,10 +174,14 @@ namespace API_LoL_Project.Controllers.version2
|
|
|
|
r,
|
|
|
|
r,
|
|
|
|
new List<EndPointLink>
|
|
|
|
new List<EndPointLink>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "self"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}", "self","POST"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}", "self","PUT"),
|
|
|
|
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}/characteristic", "self"),
|
|
|
|
|
|
|
|
EndPointLink.To($"/api/[controller]/{r.Name}/characteristic", "self"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
@ -233,12 +239,22 @@ namespace API_LoL_Project.Controllers.version2
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (value == null)
|
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var message = string.Format("Can not get champions image without the name (is empty)");
|
|
|
|
var message = string.Format("Can not get champions image without the name (is empty)");
|
|
|
|
_logger.LogWarning(message); ;
|
|
|
|
_logger.LogWarning(message); ;
|
|
|
|
return BadRequest(message);
|
|
|
|
return BadRequest(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* cannot use this GetNbItemsByName and GetItemsByName use Contains and not equals
|
|
|
|
|
|
|
|
* var totalcount = await dataManager.GetNbItemsByName(value.Name);
|
|
|
|
|
|
|
|
if (totalcount >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError("champions found with this name {name} in the dataContext | cannot add an champions with the same Name", value.Name); ;
|
|
|
|
|
|
|
|
return BadRequest("chamions this name: " + value.Name + " already exist in the dataContext champions need to have unique name");
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
// generic validation check if all field is good
|
|
|
|
// generic validation check if all field is good
|
|
|
|
var newChampion = value.ToModel();
|
|
|
|
var newChampion = value.ToModel();
|
|
|
|
await dataManager.AddItem(newChampion);
|
|
|
|
await dataManager.AddItem(newChampion);
|
|
|
@ -256,7 +272,7 @@ namespace API_LoL_Project.Controllers.version2
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
|
|
|
|
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
return BadRequest(e.Message + e.InnerException);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -390,6 +406,83 @@ namespace API_LoL_Project.Controllers.version2
|
|
|
|
var nbChampions = await dataManager.GetNbItems();
|
|
|
|
var nbChampions = await dataManager.GetNbItems();
|
|
|
|
return Ok(nbChampions);
|
|
|
|
return Ok(nbChampions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("count/class/{championClass}")]
|
|
|
|
|
|
|
|
public async Task<ActionResult<int>> GetChampionCountByClass(ChampionClass championClass)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetChampionCountByClass), championClass.GetDisplayName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var count = await dataManager.GetNbItemsByClass(championClass);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError("Something went wrong while fetching the count of champions by class in the controller: " + e.Message);
|
|
|
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("count/name/{substring}")]
|
|
|
|
|
|
|
|
public async Task<ActionResult<int>> GetNbItemsByName(string substring)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("Executing {Action} with parameters: {Substring}", nameof(GetNbItemsByName), substring);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var count = await dataManager.GetNbItemsByName(substring);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError("Something went wrong in {Action} action: {ErrorMessage}", nameof(GetNbItemsByName), e.Message);
|
|
|
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("characteristic/{characteristic}")]
|
|
|
|
|
|
|
|
public async Task<ActionResult<PageResponse<ChampionDTO>>> GetChampionByCharacteristic(string characteristic, [FromQuery] Request.PageRequest request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("Executing {Action} with parameters: {Parameters} ", nameof(GetChampionByCharacteristic), characteristic + " / " + request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var champions = await dataManager.GetItemsByCharacteristic(characteristic, request.index, request.count == 0 ? await dataManager.GetNbItems() : (int)request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerable<ChampionDTO> res = champions.Select(c => c.ToDTO());
|
|
|
|
|
|
|
|
if (res.Count() <= 0 || res == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError("No champions found for characteristic {Characteristic}", characteristic);
|
|
|
|
|
|
|
|
return BadRequest("No champions found for characteristic : " + characteristic);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var respList = res.Select(r => new LolResponse<ChampionDTO>
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
r,
|
|
|
|
|
|
|
|
new List<EndPointLink>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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 totalcount = await dataManager.GetNbItemsByCharacteristic(characteristic);
|
|
|
|
|
|
|
|
var pageResponse = new PageResponse<ChampionDTO>(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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|