|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
using DTO;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Model;
|
|
|
|
|
using API_LoL_Project.Mapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
|
|
|
|
|
@ -9,48 +11,91 @@ namespace API_LoL_Project.Controllers
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class RuneController : ControllerBase
|
|
|
|
|
{/*
|
|
|
|
|
{
|
|
|
|
|
public IRunesManager runesManager;
|
|
|
|
|
// you should create a custom logger to be prety
|
|
|
|
|
private readonly ILogger<RuneController> _logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RuneController(IDataManager dataManager,ILogger<RuneController> _logger)
|
|
|
|
|
public RuneController(IDataManager dataManager, ILogger<RuneController> logger)
|
|
|
|
|
{
|
|
|
|
|
this.runesManager = dataManager.RunesMgr;
|
|
|
|
|
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: api/<RuneController>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*// GET: api/<RuneController>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IEnumerable<RuneDTO>> Get()
|
|
|
|
|
{
|
|
|
|
|
try{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var runes = await runesManager.GetItems(0, await runesManager.GetNbItems());
|
|
|
|
|
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
|
|
|
|
|
return Ok(res);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
_logger.LogInformation("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
// GET: api/<RuneController>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<RuneDTO>>> 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<RuneDTO> 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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET api/<RuneController>/5
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public string Get(int id)
|
|
|
|
|
{
|
|
|
|
|
try{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var rune = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
RuneDto result = champion.First().toDTO();
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
catch(Exeption e){
|
|
|
|
|
catch (Exeption e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
new HttpException(400, 'Cannot get rune :' + e.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -58,14 +103,16 @@ namespace API_LoL_Project.Controllers
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Post([FromBody] string value)
|
|
|
|
|
{
|
|
|
|
|
try{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await dataManager.AddItem(value.toModel());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch(){
|
|
|
|
|
catch ()
|
|
|
|
|
{
|
|
|
|
|
new HttpException(400, 'Cannot create rune')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -80,6 +127,6 @@ namespace API_LoL_Project.Controllers
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|