Mise en place de la pagination
continuous-integration/drone/push Build is passing Details

pull/11/head
Victor Perez NGOUNOU 2 years ago
parent 555e1dd4a7
commit b61dff9eb4

@ -9,6 +9,11 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " /> <PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " /> <PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'RestFull' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\net6.0\BowlingApi.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<!--<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />--> <!--<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />-->
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />

@ -19,6 +19,7 @@ public class JoueurController:Controller
/// <summary> /// <summary>
/// Get all Players /// Get all Players
/// GET: api/joueur
/// </summary> /// </summary>
/// <returns>la liste des Joueurs </returns> /// <returns>la liste des Joueurs </returns>
/// <response code="200">Retourne la liste des joueurs</response> /// <response code="200">Retourne la liste des joueurs</response>
@ -46,13 +47,59 @@ public class JoueurController:Controller
} }
} }
/// <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<JoueurDTO>), StatusCodes.Status200OK)]
public async Task<IActionResult> Get(int page=1,int pageSize=10)
{
try
{
var result = await _joueurService.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> /// <summary>
/// Get a player by name /// Get a player by name
/// GET: api/Joueur/Djon /// GET: api/Joueur/Djon
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
/// <returns></returns> /// <response code="200">Retourne le joueur</response>
/// <response code="400">Si le nom du joueur est null</response>
/// <response code="404">Si le joueur n'existe pas</response>
/// <response code="500">Si une erreur est survenue</response>
[HttpGet("{name}")] [HttpGet("{name}")]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
[ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(JoueurDTO), StatusCodes.Status200OK)]
public async Task<IActionResult> Get(string name) public async Task<IActionResult> Get(string name)
{ {
try try
@ -74,8 +121,18 @@ public class JoueurController:Controller
} }
} }
// POST: api/Joueur /// <summary>
/// Creer un joueur
/// POST: api/Joueur
/// </summary>
/// <param name="joueur"></param>
/// <response code="201">Retourne le joueur créé</response>
/// <response code="400">Si le joueur est null</response>
/// <response code="500">Si une erreur est survenue</response>
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(JoueurDTO), StatusCodes.Status201Created)]
public async Task<ActionResult<JoueurDTO>> Post([FromBody] JoueurDTO joueur) public async Task<ActionResult<JoueurDTO>> Post([FromBody] JoueurDTO joueur)
{ {
try try
@ -95,7 +152,21 @@ public class JoueurController:Controller
} }
} }
/// <summary>
/// Modifier un joueur
/// PUT: api/Joueur/5
/// </summary>
/// <param name="id"></param>
/// <param name="joueur"></param>
/// <response code="200">Retourne le joueur modifié</response>
/// <response code="400">Si le joueur est null</response>
/// <response code="404">Si le joueur n'existe pas</response>
/// <response code="500">Si une erreur est survenue</response>
[HttpPut("{id}")] [HttpPut("{id}")]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
[ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(JoueurDTO), StatusCodes.Status200OK)]
public async Task<ActionResult<JoueurDTO>> Put(long id,[FromBody] JoueurDTO joueur) public async Task<ActionResult<JoueurDTO>> Put(long id,[FromBody] JoueurDTO joueur)
{ {
try try

@ -19,6 +19,7 @@ builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c=> builder.Services.AddSwaggerGen(c=>
{ {
c.SwaggerDoc("v1", new() { Title = "APi Bowling APP", Version = "v1" }); c.SwaggerDoc("v1", new() { Title = "APi Bowling APP", Version = "v1" });
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "BowlingApi.xml"));
}); });
builder.Services.AddAutoMapper(typeof(JoueurProfile)); builder.Services.AddAutoMapper(typeof(JoueurProfile));
builder.Services.AddScoped<IJoueurService, JoueurService>(); builder.Services.AddScoped<IJoueurService, JoueurService>();

@ -29,8 +29,6 @@
}, },
"RestFull": { "RestFull": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:5001", "applicationUrl": "https://localhost:5001",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

Binary file not shown.
Loading…
Cancel
Save