fix all
continuous-integration/drone/push Build is failing Details

Dave_Test_Api
David D'ALMEIDA 2 years ago
parent 7e119a10de
commit 5bd1f568dc

@ -4,25 +4,9 @@
{ {
public string? orderingPropertyName { get; set; } = null; public string? orderingPropertyName { get; set; } = null;
public bool? descending { get; set; } = false; public bool? descending { get; set; } = false;
// const int maxPageSize = 50; public int index { get; set; } = 0;
// public int PageNumber { get; set; } = 1;
public int index { get; set; } = 1;
public int count { get; set; } = 1; public int count { get; set; } = 1;
/*
//max lentght
private int _pageSize;
public int PageSize
{
get
{
return _pageSize;
}
set
{
_pageSize = (value > maxPageSize) ? maxPageSize : value;
}
}*/
} }
} }

@ -12,6 +12,7 @@ namespace API_LoL_Project.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class RuneController : ControllerBase public class RuneController : ControllerBase
{ {
public IRunesManager dataManager; public IRunesManager dataManager;
@ -28,7 +29,7 @@ namespace API_LoL_Project.Controllers
// GET: api/<RuneController> /*// GET: api/<RuneController>
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> GetAllRunes([FromQuery] Request.PageRequest request) public async Task<ActionResult<IEnumerable<RuneDTO>>> GetAllRunes([FromQuery] Request.PageRequest request)
{ {
@ -74,102 +75,103 @@ namespace API_LoL_Project.Controllers
return BadRequest(e.Message); return BadRequest(e.Message);
} }
} }
*/
// GET: api/<RuneController> // GET: api/<RuneController>
/* [HttpGet] /* [HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request) public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{ {
try 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);
}
}
*/
/*
[HttpGet("{name}")]
public async Task<ActionResult<LolResponce<RuneDTO>>> GetRuneByName(string name)
{ {
var totalcount = await runesManager.GetNbItems(); try
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);
} var rune = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name);
RuneDTO res = rune.First().toDTO();
if (res == null)
{
_logger.LogWarning("No runes found with {name}", name); ;
return NotFound();
}
var links = new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
};
} var response = new LolResponce<RuneDTO>(res, links);
*/ return Ok(response);
[HttpGet("{name}")]
public async Task<ActionResult<LolResponce<RuneDTO>>> GetRuneByName(string name)
{
try
{
var rune = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name);
RuneDTO res = rune.First().toDTO();
if (res == null)
{
_logger.LogWarning("No runes found with {name}", name); ;
return NotFound();
} }
var links = new List<EndPointLink> catch (Exception e)
{ {
EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
};
var response = new LolResponce<RuneDTO>(res, links);
return Ok(response);
}
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);
} }
} }*/
/* // GET api/<RuneController>/5 /* // GET api/<RuneController>/5
[HttpGet("{id}")] [HttpGet("{id}")]
public string Get(int id) public string Get(int id)
{ {
try try
{ {
var rune = await dataManager var rune = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems()); .GetItemsByName(name, 0, await dataManager.GetNbItems());
RuneDto result = champion.First().toDTO(); RuneDto result = champion.First().toDTO();
return Ok(result); return Ok(result);
} }
catch (Exeption e) catch (Exeption e)
{ {
new HttpException(400, 'Cannot get rune :' + e.message); new HttpException(400, 'Cannot get rune :' + e.message);
} }
}*/ }*/
// POST api/<RuneController> // POST api/<RuneController>
// PUT api/<RuneController>/5 // PUT api/<RuneController>/5
[HttpPut("{id}")] [HttpPut("{id}")]

@ -54,7 +54,18 @@ namespace API_LoL_Project.Mapper
} }
public static Champion ToModel(this ChampionFullDTO dto)
{
if (dto == null)
{
var message = string.Format("Champion cannot be empty");
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/
throw new Exception(message);
}
return new(dto.Name);// dto.Class, dto.Icon,
}
public static Champion ToModel(this ChampionDTO dto) public static Champion ToModel(this ChampionDTO dto)
{ {
if (dto == null) if (dto == null)

@ -19,6 +19,10 @@ namespace DTO
[StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*/ [StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*/
public string Name { get; set; } public string Name { get; set; }
public string Bio { get; set; } public string Bio { get; set; }
/* public ClassChampionDto {get; set;}*/
/* public IconDto {get; set;}*/
public ReadOnlyDictionary<string, int> Characteristics { get; set; } public ReadOnlyDictionary<string, int> Characteristics { get; set; }
public ImageDTO LargeImage { get; set; } public ImageDTO LargeImage { get; set; }

Loading…
Cancel
Save