diff --git a/Sources/BowlingApi/BowlingApi.csproj b/Sources/BowlingApi/BowlingApi.csproj
index 7f0352f..89ec037 100644
--- a/Sources/BowlingApi/BowlingApi.csproj
+++ b/Sources/BowlingApi/BowlingApi.csproj
@@ -9,6 +9,11 @@
+
+
+ 4
+ bin\Debug\net6.0\BowlingApi.xml
+
diff --git a/Sources/BowlingApi/Controllers/JoueurController.cs b/Sources/BowlingApi/Controllers/JoueurController.cs
index ffec152..1af99b7 100644
--- a/Sources/BowlingApi/Controllers/JoueurController.cs
+++ b/Sources/BowlingApi/Controllers/JoueurController.cs
@@ -19,6 +19,7 @@ public class JoueurController:Controller
///
/// Get all Players
+ /// GET: api/joueur
///
/// la liste des Joueurs
/// Retourne la liste des joueurs
@@ -46,13 +47,59 @@ public class JoueurController:Controller
}
}
+ ///
+ /// Get player with pagination
+ /// Get : api/Joueur?page=1&pageSize=10
+ ///
+ /// la liste des Joueurs
+ /// Retourne la liste des joueurs
+ /// Si la liste est vide
+ /// Si une erreur est survenue
+
+ [HttpGet("{page}/{pageSize}")]
+ [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
+ [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
+ public async Task 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;
+ }
+ }
+
///
/// Get a player by name
/// GET: api/Joueur/Djon
///
///
- ///
+ /// Retourne le joueur
+ /// Si le nom du joueur est null
+ /// Si le joueur n'existe pas
+ /// Si une erreur est survenue
[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 Get(string name)
{
try
@@ -74,8 +121,18 @@ public class JoueurController:Controller
}
}
- // POST: api/Joueur
+ ///
+ /// Creer un joueur
+ /// POST: api/Joueur
+ ///
+ ///
+ /// Retourne le joueur créé
+ /// Si le joueur est null
+ /// Si une erreur est survenue
[HttpPost]
+ [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(typeof(JoueurDTO), StatusCodes.Status201Created)]
public async Task> Post([FromBody] JoueurDTO joueur)
{
try
@@ -95,7 +152,21 @@ public class JoueurController:Controller
}
}
+ ///
+ /// Modifier un joueur
+ /// PUT: api/Joueur/5
+ ///
+ ///
+ ///
+ /// Retourne le joueur modifié
+ /// Si le joueur est null
+ /// Si le joueur n'existe pas
+ /// Si une erreur est survenue
[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> Put(long id,[FromBody] JoueurDTO joueur)
{
try
diff --git a/Sources/BowlingApi/Program.cs b/Sources/BowlingApi/Program.cs
index e357277..59e1f46 100644
--- a/Sources/BowlingApi/Program.cs
+++ b/Sources/BowlingApi/Program.cs
@@ -19,6 +19,7 @@ builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c=>
{
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.AddScoped();
diff --git a/Sources/BowlingApi/Properties/launchSettings.json b/Sources/BowlingApi/Properties/launchSettings.json
index fc48bb7..cfd4403 100644
--- a/Sources/BowlingApi/Properties/launchSettings.json
+++ b/Sources/BowlingApi/Properties/launchSettings.json
@@ -29,8 +29,6 @@
},
"RestFull": {
"commandName": "Project",
- "dotnetRunMessages": true,
- "launchBrowser": false,
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
diff --git a/Sources/BowlingApi/bowling.db b/Sources/BowlingApi/bowling.db
index 79e15c6..f7bb14f 100644
Binary files a/Sources/BowlingApi/bowling.db and b/Sources/BowlingApi/bowling.db differ