|
|
@ -1,6 +1,7 @@
|
|
|
|
using ApiLol.Mapper;
|
|
|
|
using ApiLol.Mapper;
|
|
|
|
using DTO;
|
|
|
|
using DTO;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
using Model;
|
|
|
|
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
|
|
|
@ -24,24 +25,38 @@ namespace ApiLol.Controllers
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
public async Task<IActionResult> Get([FromQuery] PageRequest pageRequest)
|
|
|
|
public async Task<IActionResult> Get([FromQuery] PageRequest pageRequest)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("Executing {Action} - SKIN with parameters: {Parameters}", nameof(Get), pageRequest.count);
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int nbTotal = await _manager.ChampionsMgr.GetNbItems();
|
|
|
|
int nbTotal = await _manager.SkinsMgr.GetNbItems();
|
|
|
|
if (pageRequest.count + pageRequest.index > nbTotal)
|
|
|
|
if (pageRequest.count == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogWarning($"too many, maximum {nbTotal}");
|
|
|
|
pageRequest = new PageRequest() { index = 0, count = nbTotal, orderingPropertyName = pageRequest.orderingPropertyName, descending = pageRequest.descending, name = pageRequest.name };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (pageRequest.count * pageRequest.index >= nbTotal || pageRequest.count > nbTotal)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogWarning("too many, maximum {number}", nbTotal);
|
|
|
|
return BadRequest($"Champion limit exceed, max {nbTotal}");
|
|
|
|
return BadRequest($"Champion limit exceed, max {nbTotal}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"method Get call");
|
|
|
|
IEnumerable<SkinDtoC> dtos;
|
|
|
|
IEnumerable<SkinDtoC> dtos = (await _manager.SkinsMgr.GetItems(pageRequest.index, pageRequest.count))
|
|
|
|
if (pageRequest.name == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dtos = (await _manager.SkinsMgr.GetItems(pageRequest.index, pageRequest.count, pageRequest.orderingPropertyName, pageRequest.descending))
|
|
|
|
.Select(x => x.ToDtoC());
|
|
|
|
.Select(x => x.ToDtoC());
|
|
|
|
return Ok(dtos);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dtos = (await _manager.SkinsMgr.GetItemsByName(pageRequest.name, pageRequest.index, pageRequest.count, pageRequest.orderingPropertyName, pageRequest.descending))
|
|
|
|
|
|
|
|
.Select(x => x.ToDtoC());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(new { Data = dtos, index = pageRequest.index, count = pageRequest.count, total = nbTotal });
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception error)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
_logger.LogError(error.Message);
|
|
|
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -49,28 +64,120 @@ namespace ApiLol.Controllers
|
|
|
|
[HttpGet("{name}")]
|
|
|
|
[HttpGet("{name}")]
|
|
|
|
public async Task<IActionResult> Get(string name)
|
|
|
|
public async Task<IActionResult> Get(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Ok();
|
|
|
|
_logger.LogInformation("method {Action} - SKIN call with {name}", nameof(Get), name);
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dtos = (await _manager.SkinsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()))
|
|
|
|
|
|
|
|
.Select(x => x.ToDtoC());
|
|
|
|
|
|
|
|
if (dtos.IsNullOrEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogWarning($"{name} was not found");
|
|
|
|
|
|
|
|
return NotFound($"{name} was not found");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(dtos.First());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError(error.Message);
|
|
|
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST api/<SkinsController>
|
|
|
|
// POST api/<SkinsController>
|
|
|
|
[HttpPost]
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<IActionResult> Post([FromBody] string value)
|
|
|
|
public async Task<IActionResult> Post([FromBody] SkinDtoC skin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Ok();
|
|
|
|
_logger.LogInformation("method {Action} - SKIN call with {item}", nameof(Post), skin);
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (skin.ChampionName != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemByName(skin.ChampionName, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
|
|
|
|
if (dtos.IsNullOrEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogWarning($"Champion Name : {skin.ChampionName} not exist");
|
|
|
|
|
|
|
|
return BadRequest($"Champion Name : {skin.ChampionName} not exist");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (await _manager.SkinsMgr.GetNbItemsByName(skin.Name) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(Get),
|
|
|
|
|
|
|
|
(await _manager.SkinsMgr.AddItem(skin.ToModelC(dtos.First()))).ToDtoC());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.LogWarning($"Name : {skin.Name} is already exist");
|
|
|
|
|
|
|
|
return BadRequest($"Name : {skin.Name} is already exist");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return BadRequest("Please fill in the name of the champion");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError(error.Message);
|
|
|
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PUT api/<SkinsController>/5
|
|
|
|
// PUT api/<SkinsController>/5
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
public async Task<IActionResult> Put(int id, [FromBody] string value)
|
|
|
|
public async Task<IActionResult> Put(string name, [FromBody] SkinDtoC skin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Ok();
|
|
|
|
_logger.LogInformation("method {Action} - SKIN call with {name} and {item}", nameof(Put), name, skin);
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dtos = (await _manager.SkinsMgr.GetItemByName(name, 0, await _manager.SkinsMgr.GetNbItems()));
|
|
|
|
|
|
|
|
if (dtos.IsNullOrEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return NotFound($"Name {name} not exist");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks if the new name exists
|
|
|
|
|
|
|
|
if (name != skin.Name)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dtos2 = (await _manager.SkinsMgr.GetItemByName(skin.Name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
|
|
|
|
if (dtos2.IsNullOrEmpty() || dtos2.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return BadRequest($"New Name {skin.Name} is already exist");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var dtosChampion = (await _manager.ChampionsMgr.GetItemByName(skin.ChampionName, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
|
|
|
|
if (dtosChampion.IsNullOrEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogWarning($"Champion Name : {skin.ChampionName} not exist");
|
|
|
|
|
|
|
|
return BadRequest($"Champion Name : {skin.ChampionName} not exist");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok((await _manager.SkinsMgr.UpdateItem(dtos.First(), skin.ToModelC(dtosChampion.First()))).ToDtoC());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError(error.Message);
|
|
|
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DELETE api/<SkinsController>/5
|
|
|
|
// DELETE api/<SkinsController>/5
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Ok();
|
|
|
|
_logger.LogInformation("method {Action} - Skin call with {name}", nameof(Delete), name);
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dtos = (await _manager.SkinsMgr.GetItemByName(name, 0, await _manager.SkinsMgr.GetNbItems()));
|
|
|
|
|
|
|
|
if (dtos.IsNullOrEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogWarning("{name} was not found", name);
|
|
|
|
|
|
|
|
return BadRequest();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(await _manager.SkinsMgr.DeleteItem(dtos.First()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError(error.Message);
|
|
|
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|