pull/4/head
kekentin 1 month ago
commit 2c2e09704d

@ -0,0 +1,23 @@
image: mcr.microsoft.com/dotnet/sdk:8.0
volumes:
- name: docs
path: /docs
- dotnet new tool-manifest
- dotnet tool install NSwag.ConsoleCore
- dotnet nswag aspnetcore2openapi /output:/docs/swagger.json
volumes:
- name: docs
temp: {}
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer
volumes:
- name: docs
path: /docs
commands:
- /entrypoint.sh
depends_on: [ previous_job_name ]

@ -35,7 +35,7 @@ namespace Shared
// Updates the details of an existing user identified by 'userId'.
// 'userId' is the ID of the user to be updated, and 'user' contains the new user data.
Task<TUser> UpdateUser(int userId, TUser user, TUser existingUser);
Task<TUser> UpdateUser(int userId, TUser user);
// Removes a user from the system based on their unique identifier ('userId').
// 'userId' is the unique identifier of the user to be removed.

@ -36,7 +36,7 @@ namespace StubApi
public async Task AddUser(UserDTO user)
{
throw new NotImplementedException();
_users.Add(user);
}
public async Task<int> CountUser()
@ -94,7 +94,7 @@ namespace StubApi
public async Task RemoveUser(UserDTO user)
{
throw new NotImplementedException();
_users.Remove(user);
}
public async Task SetAdminRole(bool isAdmin)
@ -104,16 +104,19 @@ namespace StubApi
public async Task<UserDTO> UpdateUser(int userId, UserDTO user, UserDTO existingUser)
public async Task<UserDTO> UpdateUser(int userId, UserDTO user)
{
UserDTO userUpdate = new UserDTO();
userUpdate = GetUserById(userId).Result;
// Update users properties
existingUser.Pseudo = user.Pseudo;
existingUser.Password = user.Password;
existingUser.Email = user.Email;
existingUser.date = user.date;
existingUser.ImageProfil = user.ImageProfil;
return existingUser;
userUpdate.Pseudo = user.Pseudo;
userUpdate.Password = user.Password;
userUpdate.Email = user.Email;
userUpdate.date = user.date;
userUpdate.ImageProfil = user.ImageProfil;
return userUpdate;
}
}
}

@ -21,8 +21,34 @@ namespace WfApi.Controllers
}
//===================================== ROUTE GET =====================================
[HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL
/// <summary>
/// Gets a user by their unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the user</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/{id}
///
/// Where `{id}` is the unique identifier of the user you want to retrieve.
///
/// ## **Returns**
///
/// - **200 OK** : Returns the user data if the user with the given ID exists.
/// - **204 No Content** : No user found for the provided ID, or the operation failed.
/// - **500 Internal Server Error** : If there is an exception during the process.
///
/// ## **Error Handling**
/// - In case of an internal server error (e.g., database issues), a `500 Internal Server Error` will be returned with an error message.
/// </remarks>
/// <response code="200">Returns the user data corresponding to the provided ID</response>
/// <response code="204">No content if no user is found or the operation fails</response>
/// <response code="500">Internal server error in case of an exception</response>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpGet("{id}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> Get(int id)
{
try
@ -45,7 +71,35 @@ namespace WfApi.Controllers
}
[HttpGet("all")] // Indiquer que l'id est dans l'URL
/// <summary>
/// Gets a list of users with pagination support.
/// </summary>
/// <param name="index">The index of the page to retrieve (default is 0)</param>
/// <param name="count">The number of users to retrieve per page (default is 5)</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/all?index=0&count=5
///
/// The `index` parameter specifies the page number to retrieve (starting from 0), and the `count` parameter specifies how many users to return per page.
///
/// ## **Returns**
///
/// - **200 OK** : Returns a list of users if the operation is successful.
/// - **204 No Content** : If no users are found or the operation fails.
/// - **500 Internal Server Error** : If there is an exception during the execution of the request.
///
/// ## **Error Handling**
/// - In case of an internal server error (e.g., database issues), a `500 Internal Server Error` is returned with an error message.
/// </remarks>
/// <response code="200">Returns a list of users</response>
/// <response code="204">No content if no users are found or the operation fails</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("all")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetAllUsers(int index = 0, int count = 5)
{
try
@ -68,9 +122,45 @@ namespace WfApi.Controllers
}
[HttpGet("hashpassword/{username}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> GetHashPassword(string username)
/// <summary>
/// Gets the hashed password for a given username.
/// </summary>
/// <param name="username">The username to retrieve the hashed password for</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/hashpassword?username=johndoe
///
/// The `username` parameter specifies the username for which to retrieve the hashed password.
///
/// ## **Returns**
///
/// - **200 OK** : Returns the hashed password for the user if the username exists.
/// - **400 Bad Request** : If no username is provided or if the username is invalid.
/// - **204 No Content** : If no hashed password is found for the provided username.
/// - **500 Internal Server Error** : If an exception occurs while processing the request.
///
/// ## **Error Handling**
/// - In case of a missing or invalid `username`, a `400 Bad Request` is returned with a relevant message.
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned.
/// </remarks>
/// <response code="200">Returns the hashed password for the provided username</response>
/// <response code="400">Bad request if no username is provided or invalid</response>
/// <response code="204">No content if no hashed password is found</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("hashpassword")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetHashPassword([FromQuery] string username)
{
if (string.IsNullOrWhiteSpace(username))
{
return BadRequest(new { message = "No user defined" });
}
try
{
var result = _user.GetHashPassword(username);
@ -91,9 +181,45 @@ namespace WfApi.Controllers
}
[HttpGet("username/{username}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> GetUserByUsername(string username)
/// <summary>
/// Gets a user by their username.
/// </summary>
/// <param name="username">The username to retrieve the user</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/username?username=johndoe
///
/// The `username` parameter specifies the username of the user you want to retrieve.
///
/// ## **Returns**
///
/// - **200 OK** : Returns the user data if the username exists.
/// - **400 Bad Request** : If no username is provided or if the username is invalid.
/// - **204 No Content** : If no user is found with the provided username.
/// - **500 Internal Server Error** : If an exception occurs while processing the request.
///
/// ## **Error Handling**
/// - In case of a missing or invalid `username`, a `400 Bad Request` is returned with a relevant message.
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned.
/// </remarks>
/// <response code="200">Returns the user data for the provided username</response>
/// <response code="400">Bad request if no username is provided or invalid</response>
/// <response code="204">No content if no user is found with the provided username</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("username")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetUserByUsername([FromQuery] string username)
{
if (string.IsNullOrWhiteSpace(username))
{
return BadRequest(new { message = "No user defined" });
}
try
{
var result = _user.GetUserByUsername(username);
@ -112,9 +238,46 @@ namespace WfApi.Controllers
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
[HttpGet("email/{email}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> GetUserByEmail(string email)
/// <summary>
/// Gets a user by their email address.
/// </summary>
/// <param name="email">The email address of the user</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/email?email=johndoe@example.com
///
/// The `email` parameter specifies the email address of the user you want to retrieve.
///
/// ## **Returns**
///
/// - **200 OK** : Returns the user data if the email exists.
/// - **400 Bad Request** : If no email is provided or if the email is invalid.
/// - **204 No Content** : If no user is found with the provided email.
/// - **500 Internal Server Error** : If an exception occurs while processing the request.
///
/// ## **Error Handling**
/// - In case of a missing or invalid `email`, a `400 Bad Request` is returned with a relevant message.
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned.
/// </remarks>
/// <response code="200">Returns the user data for the provided email</response>
/// <response code="400">Bad request if no email is provided or invalid</response>
/// <response code="204">No content if no user is found with the provided email</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("email")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetUserByEmail([FromQuery] string email)
{
if (string.IsNullOrWhiteSpace(email))
{
return BadRequest(new { message = "No user email defined" });
}
try
{
var result = _user.GetUserByEmail(email);
@ -135,7 +298,33 @@ namespace WfApi.Controllers
}
[HttpGet("countuser")] // Indiquer que l'id est dans l'URL
/// <summary>
/// Gets the total number of users.
/// </summary>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/count
///
/// This endpoint returns the total number of users present in the system.
///
/// ## **Returns**
///
/// - **200 OK** : Returns the total count of users.
/// - **204 No Content** : If no users are found or the operation fails.
/// - **500 Internal Server Error** : If an exception occurs while processing the request.
///
/// ## **Error Handling**
/// - In case of an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with a relevant message.
/// </remarks>
/// <response code="200">Returns the total count of users</response>
/// <response code="204">No content if the count could not be retrieved</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("count")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetCountUser()
{
try
@ -159,9 +348,45 @@ namespace WfApi.Controllers
[HttpGet("existusername/{username}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> GetExistUsername(string username)
/// <summary>
/// Checks if a user exists by their username.
/// </summary>
/// <param name="username">The username to check for existence</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/existusername?username=johndoe
///
/// The `username` parameter specifies the username to check if it exists in the system.
///
/// ## **Returns**
///
/// - **200 OK** : If the username exists, returns a success message.
/// - **400 Bad Request** : If no username is provided or if the username is invalid.
/// - **404 Not Found** : If the user with the specified username does not exist.
/// - **500 Internal Server Error** : If an exception occurs while processing the request.
///
/// ## **Error Handling**
/// - In case of a missing or invalid `username`, a `400 Bad Request` is returned with a relevant message.
/// - If the user does not exist, a `404 Not Found` response is returned.
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message.
/// </remarks>
/// <response code="200">Returns a success message if the username exists</response>
/// <response code="400">Bad request if no username is provided or invalid</response>
/// <response code="404">Not found if the user with the provided username does not exist</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("existusername")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetExistUsername([FromQuery] string username)
{
if (string.IsNullOrWhiteSpace(username))
{
return BadRequest(new { message = "No user defined" });
}
try
{
var result = _user.ExistUsername(username);
@ -172,7 +397,7 @@ namespace WfApi.Controllers
}
else
{
return NoContent();
return NotFound("User not found");
}
}
catch (Exception)
@ -182,9 +407,45 @@ namespace WfApi.Controllers
}
[HttpGet("existemail/{email}")] // Indiquer que l'id est dans l'URL
public async Task<IActionResult> GetExistEmail(string email)
/// <summary>
/// Checks if a user exists by their email address.
/// </summary>
/// <param name="email">The email address to check for existence</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// GET /users/existemail?email=johndoe@example.com
///
/// The `email` parameter specifies the email address to check if it exists in the system.
///
/// ## **Returns**
///
/// - **200 OK** : If the email exists, returns a success message.
/// - **400 Bad Request** : If no email is provided or if the email is invalid.
/// - **404 Not Found** : If the user with the specified email does not exist.
/// - **500 Internal Server Error** : If an exception occurs while processing the request.
///
/// ## **Error Handling**
/// - In case of a missing or invalid `email`, a `400 Bad Request` is returned with a relevant message.
/// - If the user does not exist, a `404 Not Found` response is returned.
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message.
/// </remarks>
/// <response code="200">Returns a success message if the email exists</response>
/// <response code="400">Bad request if no email is provided or invalid</response>
/// <response code="404">Not found if the user with the provided email does not exist</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpGet("existemail")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetExistEmail([FromQuery] string email)
{
if (string.IsNullOrWhiteSpace(email))
{
return BadRequest(new { message = "No user email defined" });
}
try
{
var result = _user.ExistEmail(email);
@ -195,7 +456,7 @@ namespace WfApi.Controllers
}
else
{
return NoContent();
return NotFound("User email not found");
}
}
catch (Exception)
@ -207,7 +468,42 @@ namespace WfApi.Controllers
//===================================== ROUTE PUT =====================================
/// <summary>
/// Updates an existing user's data.
/// </summary>
/// <param name="id">The ID of the user to update</param>
/// <param name="updateduser">The updated user data</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// PUT /users?id=1
/// Body:
/// {
/// "username": "newusername",
/// "email": "newemail@example.com",
/// "fullName": "New Name"
/// }
///
/// The `id` parameter specifies the user ID to be updated, and the body contains the updated user data.
///
/// ## **Returns**
///
/// - **200 OK** : If the user was successfully updated.
/// - **400 Bad Request** : If the provided user data is invalid or missing.
/// - **500 Internal Server Error** : If an error occurs while processing the update.
///
/// ## **Error Handling**
/// - If the `updateduser` object is `null`, a `400 Bad Request` is returned with a message indicating that player data is required.
/// - If an exception occurs during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message.
/// </remarks>
/// <response code="200">Returns the updated user data</response>
/// <response code="400">Bad request if no user data is provided or invalid</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpPut()]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> UpdateUser([FromQuery] int id, [FromBody] UserDTO updateduser)
{
try
@ -217,18 +513,11 @@ namespace WfApi.Controllers
return BadRequest(new { message = "Player data is required." });
}
var existingUser = _user.GetUserById(id).Result;
if (existingUser == null)
{
return NotFound(new { message = "Player not found." });
}
var result = _user.UpdateUser(id,updateduser,existingUser);
var result = _user.UpdateUser(id,updateduser);
return Ok(result);
}
catch (Exception ex)
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." });
}
@ -238,8 +527,47 @@ namespace WfApi.Controllers
//===================================== ROUTE POST =====================================
/// <summary>
/// Creates a new user in the system.
/// </summary>
/// <param name="newUser">The user data to create the new user</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// POST /users
/// Body:
/// {
/// "id": 123,
/// "username": "newuser",
/// "email": "newuser@example.com",
/// "fullName": "New User"
/// }
///
/// The `newUser` parameter in the body contains the data of the new user to be created.
///
/// ## **Returns**
///
/// - **201 Created** : If the user was successfully created. The location of the created resource is returned in the response header.
/// - **400 Bad Request** : If the provided user data is invalid or missing.
/// - **409 Conflict** : If a user with the specified ID already exists.
/// - **500 Internal Server Error** : If an error occurs while processing the creation of the user.
///
/// ## **Error Handling**
/// - If the `newUser` object is `null`, a `400 Bad Request` is returned with a message indicating that user data is required.
/// - If the user already exists (based on `Id`), a `409 Conflict` is returned with a message indicating that a user with this ID already exists.
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message.
/// </remarks>
/// <response code="201">Returns the created user and its location</response>
/// <response code="400">Bad request if no user data is provided or invalid</response>
/// <response code="409">Conflict if a user with the same ID already exists</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpPost]
public async Task<IActionResult> CreatePlayer([FromBody] UserDTO newUser)
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateUser([FromBody] UserDTO newUser)
{
try
{
@ -258,7 +586,7 @@ namespace WfApi.Controllers
return CreatedAtAction(nameof(GetAllUsers), new { id = newUser.Id }, newUser);
}
catch (Exception ex)
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." });
}
@ -268,7 +596,35 @@ namespace WfApi.Controllers
//===================================== ROUTE DELETE =====================================
/// <summary>
/// Deletes a player by their ID.
/// </summary>
/// <param name="id">The ID of the player to be deleted</param>
/// <returns></returns>
/// <remarks>
/// ## **Sample request**:
///
/// DELETE /api/v1/players?id=51
///
/// The `id` parameter specifies the ID of the player to be deleted.
///
/// ## **Returns**
///
/// - **200 OK** : If the player was successfully deleted, a success message is returned.
/// - **404 Not Found** : If no player with the given ID is found.
/// - **500 Internal Server Error** : If an error occurs while deleting the player.
///
/// ## **Error Handling**
/// - If no player is found with the specified `id`, a `404 Not Found` response is returned with a message "Player not found."
/// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` response is returned with a message "Internal server error."
/// </remarks>
/// <response code="200">Returns a success message indicating the player was deleted</response>
/// <response code="404">Not found if no player with the specified ID is found</response>
/// <response code="500">Internal server error in case of an exception</response>
[HttpDelete] // /api/v1/players?id=51
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeletePlayer([FromQuery] int id)
{
try
@ -284,12 +640,10 @@ namespace WfApi.Controllers
return Ok(new { message = $"Player {id} deleted successfully." });
}
catch (Exception ex)
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." });
}
}
}
}

Loading…
Cancel
Save