finishh pagination
continuous-integration/drone/push Build is failing Details

EFManagers
Lucas Delanier 2 years ago
parent 70fa29f29a
commit 652d47c40e

@ -0,0 +1,13 @@
namespace APILOL.Controllers.Request
{
public class PageResponse
{
public bool IsDesc { get; set; } = false;
public int Offset { get; set; } = 0;
public string? OrderingPropertyName { get; set; } = "Name";
public int Limit { get; set; } = 10;
}
}

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

@ -30,7 +30,7 @@ namespace APILOL.Controllers.v1
// GET: api/<RuneController> // GET: api/<RuneController>
[MapToApiVersion("1.0")] [MapToApiVersion("1.0")]
[HttpGet] [HttpGet]
public async Task<IActionResult> Get([FromQuery] PageRequest request) public async Task<IActionResult> Get([FromQuery] PageResponse request)
{ {
_logger.LogInformation("API call - [GET] - RUNE"); _logger.LogInformation("API call - [GET] - RUNE");
try try
@ -44,7 +44,7 @@ namespace APILOL.Controllers.v1
_logger.LogInformation("No rune found."); _logger.LogInformation("No rune found.");
return NotFound("No rune found."); return NotFound("No rune found.");
} }
return Ok(items); return Ok(new { data = items, count = await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit });
} }
catch (Exception error) catch (Exception error)
{ {

@ -44,7 +44,7 @@ namespace APILOL.Controllers.v1
_logger.LogInformation("No runePage found."); _logger.LogInformation("No runePage found.");
return NotFound("No runePage found."); return NotFound("No runePage found.");
} }
return Ok(items); return Ok(new { data = items, count = await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit });
} }
catch (Exception error) catch (Exception error)
{ {

@ -42,7 +42,7 @@ namespace APILOL.Controllers.v1
_logger.LogInformation("No skin found."); _logger.LogInformation("No skin found.");
return NotFound("No skin found."); return NotFound("No skin found.");
} }
return Ok(items); return Ok(new { data = items, count = await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit });
} }
catch (Exception error) catch (Exception error)
{ {

@ -47,7 +47,7 @@ namespace APILOL.Controllers.v2
_logger.LogInformation("No champion found."); _logger.LogInformation("No champion found.");
return NotFound("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) catch(Exception error)
{ {

@ -44,7 +44,7 @@ namespace APILOL.Controllers.v2
_logger.LogInformation("No rune found."); _logger.LogInformation("No rune found.");
return NotFound("No rune found."); return NotFound("No rune found.");
} }
return Ok(items); return Ok(new { data = items, count = await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit });
} }
catch (Exception error) catch (Exception error)
{ {

@ -44,7 +44,7 @@ namespace APILOL.Controllers.v2
_logger.LogInformation("No runePage found."); _logger.LogInformation("No runePage found.");
return NotFound("No runePage found."); return NotFound("No runePage found.");
} }
return Ok(items); return Ok(new { data = items, count = await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit });
} }
catch (Exception error) catch (Exception error)
{ {

@ -42,7 +42,7 @@ namespace APILOL.Controllers.v2
_logger.LogInformation("No skin found."); _logger.LogInformation("No skin found.");
return NotFound("No skin found."); return NotFound("No skin found.");
} }
return Ok(items); return Ok(new { data = items, count = await dataManager.GetNbItems(), offset = request.Offset, limit = request.Limit });
} }
catch (Exception error) catch (Exception error)
{ {

@ -28,7 +28,7 @@ namespace TestUnitaire
public async Task TestGet() public async Task TestGet()
{ {
//Act //Act
var champions = await controller.Get(new PageRequest()); var champions = await controller.Get(new PageResponse());
//Assert //Assert
var resultObject = champions as OkObjectResult; var resultObject = champions as OkObjectResult;

Loading…
Cancel
Save