|
|
@ -6,14 +6,16 @@ using Model;
|
|
|
|
|
|
|
|
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
|
|
|
|
|
|
|
|
namespace ApiLol.Controllers
|
|
|
|
namespace ApiLol.Controllers.v2
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
[ApiVersion("2.0")]
|
|
|
|
|
|
|
|
[ApiVersion("3.0")]
|
|
|
|
|
|
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
|
|
[ApiController]
|
|
|
|
[ApiController]
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IDataManager _manager;
|
|
|
|
private readonly IDataManager _manager;
|
|
|
|
public readonly ILogger<ChampionsController> _logger;
|
|
|
|
private readonly ILogger<ChampionsController> _logger;
|
|
|
|
public ChampionsController(IDataManager dataManager, ILogger<ChampionsController> logger)
|
|
|
|
public ChampionsController(IDataManager dataManager, ILogger<ChampionsController> logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
@ -27,7 +29,7 @@ namespace ApiLol.Controllers
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int nbTotal = await _manager.ChampionsMgr.GetNbItems();
|
|
|
|
int nbTotal = await _manager.ChampionsMgr.GetNbItems();
|
|
|
|
if (pageRequest.count + pageRequest.index > nbTotal)
|
|
|
|
if (pageRequest.count * pageRequest.index >= nbTotal)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogWarning($"too many, maximum {nbTotal}");
|
|
|
|
_logger.LogWarning($"too many, maximum {nbTotal}");
|
|
|
|
return BadRequest($"Champion limit exceed, max {nbTotal}");
|
|
|
|
return BadRequest($"Champion limit exceed, max {nbTotal}");
|
|
|
@ -41,7 +43,35 @@ namespace ApiLol.Controllers
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: api/<ValuesController>
|
|
|
|
|
|
|
|
[HttpGet, MapToApiVersion("3.0")]
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetV3([FromQuery] PageRequest pageRequest)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int nbTotal = await _manager.ChampionsMgr.GetNbItems();
|
|
|
|
|
|
|
|
if (pageRequest == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pageRequest.index = 0;
|
|
|
|
|
|
|
|
pageRequest.count = nbTotal;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (pageRequest.count * pageRequest.index >= nbTotal)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogWarning($"too many, maximum {nbTotal}");
|
|
|
|
|
|
|
|
return BadRequest($"Champion limit exceed, max {nbTotal}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"method Get call");
|
|
|
|
|
|
|
|
IEnumerable<ChampionDto> dtos = (await _manager.ChampionsMgr.GetItems(pageRequest.index, pageRequest.count))
|
|
|
|
|
|
|
|
.Select(x => x.ToDto());
|
|
|
|
|
|
|
|
return Ok(dtos);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -64,7 +94,6 @@ namespace ApiLol.Controllers
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -86,7 +115,6 @@ namespace ApiLol.Controllers
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -100,13 +128,13 @@ namespace ApiLol.Controllers
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
if (dtos.IsNullOrEmpty())
|
|
|
|
if (dtos.IsNullOrEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest("Name not exist");
|
|
|
|
return NotFound("Name not exist");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Checks if the new name exists
|
|
|
|
// Checks if the new name exists
|
|
|
|
if (name != champion.Name)
|
|
|
|
if (name != champion.Name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var dtos2 = (await _manager.ChampionsMgr.GetItemsByName(champion.Name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
var dtos2 = (await _manager.ChampionsMgr.GetItemsByName(champion.Name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
if (!dtos.IsNullOrEmpty())
|
|
|
|
if (dtos.IsNullOrEmpty() || dtos2.Count() > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest("Name is already exist");
|
|
|
|
return BadRequest("Name is already exist");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -116,12 +144,11 @@ namespace ApiLol.Controllers
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("/{name}/skins")]
|
|
|
|
[HttpGet("/{name}/skins")]
|
|
|
|
public async Task<ActionResult<Skin>> GetChampionsSkins(string name)
|
|
|
|
public async Task<ActionResult<SkinDto>> GetChampionsSkins(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -134,12 +161,11 @@ namespace ApiLol.Controllers
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("/{name}/skills")]
|
|
|
|
[HttpGet("/{name}/skills")]
|
|
|
|
public async Task<ActionResult<Skin>> GetChampionsSkills(string name)
|
|
|
|
public async Task<ActionResult<SkillDto>> GetChampionsSkills(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|