|
|
|
@ -121,6 +121,43 @@ namespace BowlingApi.Controllers
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}/// <summary>
|
|
|
|
|
/// Get player with pagination
|
|
|
|
|
/// Get : api/Joueur?page=1&pageSize=10
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>la liste des Joueurs </returns>
|
|
|
|
|
/// <response code="200">Retourne la liste des joueurs</response>
|
|
|
|
|
/// <response code="404">Si la liste est vide</response>
|
|
|
|
|
/// <response code="500">Si une erreur est survenue</response>
|
|
|
|
|
|
|
|
|
|
[HttpGet("{page}/{pageSize}")]
|
|
|
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
|
|
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<PartieDTO>), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> Get(int page = 1, int pageSize = 10)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await _partieService.GetAll();
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
var data = result.Skip((page - 1) * pageSize).Take(pageSize);
|
|
|
|
|
Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(new
|
|
|
|
|
{
|
|
|
|
|
totalCount = result.Count(),
|
|
|
|
|
pageSize = pageSize,
|
|
|
|
|
currentPage = page,
|
|
|
|
|
totalPages = (int)Math.Ceiling(result.Count() / (double)pageSize)
|
|
|
|
|
}));
|
|
|
|
|
return Ok(data);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|