|
|
|
@ -34,7 +34,7 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> Get([FromQuery] PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("API call - [GET] - CHAMPION");
|
|
|
|
|
_logger.LogInformation("API call - [GET] - CHAMPION ");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -43,13 +43,14 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
IEnumerable<ChampionDTO> items = champions.Select(c => c.ToDto());
|
|
|
|
|
if (items.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("No champion found.");
|
|
|
|
|
_logger.LogError("No champion found.");
|
|
|
|
|
return NotFound("No champion found.");
|
|
|
|
|
}
|
|
|
|
|
return Ok(items);
|
|
|
|
|
return Ok(new {data= items,count= await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit});
|
|
|
|
|
}
|
|
|
|
|
catch(Exception error)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Error in the request");
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -60,7 +61,7 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
[HttpGet("{name}")]
|
|
|
|
|
public async Task<IActionResult> Get([FromQuery] PageRequest request,string name)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("API call - [GET / NAME] - CHAMPION");
|
|
|
|
|
_logger.LogInformation("API call - [GET / NAME] - CHAMPION {name}", name);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (dataManager.GetNbItemsByName(name) != null)
|
|
|
|
@ -69,16 +70,17 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
IEnumerable <ChampionDTO> items = champions.Select(c => c.ToDto());
|
|
|
|
|
if (items.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("No champion found.");
|
|
|
|
|
_logger.LogError("No champion found.");
|
|
|
|
|
return NotFound("No champion found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(items);
|
|
|
|
|
return Ok(new {data= items,count= dataManager.GetNbItems()});
|
|
|
|
|
}
|
|
|
|
|
return NotFound("No champion matching with this name.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Error in the request");
|
|
|
|
|
return BadRequest(error.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -97,7 +99,7 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
await dataManager.AddItem(championDTO.ToModel());
|
|
|
|
|
return CreatedAtAction(nameof(Get), championDTO);
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("A champion already exist with this Name. ( Unique Name )");
|
|
|
|
|
_logger.LogError("A champion already exist with this Name. ( Unique Name )");
|
|
|
|
|
return BadRequest("A champion already exist with this Name. ( Unique Name )");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception error)
|
|
|
|
@ -128,13 +130,13 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
return Ok();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("champion already exist with this unique name.");
|
|
|
|
|
_logger.LogError("champion already exist with this unique name.");
|
|
|
|
|
return BadRequest("champion already exist with this unique name.");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("champion not found.");
|
|
|
|
|
_logger.LogError("champion not found.");
|
|
|
|
|
return NotFound("champion not found.");
|
|
|
|
|
}
|
|
|
|
|
await dataManager.UpdateItem(champion.First(), championDTO.ToModel());
|
|
|
|
@ -143,6 +145,7 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Error in the request");
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -166,13 +169,14 @@ namespace APILOL.Controllers.v1
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("No matching Champion with this name");
|
|
|
|
|
_logger.LogError("No matching Champion with this name");
|
|
|
|
|
return NotFound("No matching Champion with this name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch(Exception error)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Error in the request");
|
|
|
|
|
return BadRequest(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|