You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.3 KiB
141 lines
4.3 KiB
using DTO;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shared;
|
|
using System.Net;
|
|
namespace WfApi.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/users")] //Version API
|
|
|
|
public class UsersController : ControllerBase
|
|
{
|
|
private readonly IUserService<UserDTO> _user;
|
|
|
|
private readonly ILogger<UsersController> _logger;
|
|
public UsersController(IUserService<UserDTO> userService, ILogger<UsersController> logger)
|
|
{
|
|
_user = userService;
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
//===================================== ROUTE GET =====================================
|
|
|
|
[HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL
|
|
public async Task<IActionResult> Get(int id)
|
|
{
|
|
try
|
|
{
|
|
var result = _user.GetUserById(id);
|
|
|
|
if(result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
|
|
|
|
[HttpGet("all")] // Indiquer que l'id est dans l'URL
|
|
public async Task<IActionResult> GetAllUsers(int index =0, int count = 5)
|
|
{
|
|
try
|
|
{
|
|
var result = _user.GetSomeUser(index, count);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
|
|
|
|
[HttpGet("hashpassword/{username}")] // Indiquer que l'id est dans l'URL
|
|
public async Task<IActionResult> GetHashPassword(string username)
|
|
{
|
|
try
|
|
{
|
|
var result = _user.GetHashPassword(username);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
|
|
|
|
[HttpGet("username/{username}")] // Indiquer que l'id est dans l'URL
|
|
public async Task<IActionResult> GetUserByUsername(string username)
|
|
{
|
|
try
|
|
{
|
|
var result = _user.GetUserByUsername(username);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
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)
|
|
{
|
|
try
|
|
{
|
|
var result = _user.GetUserByEmail(email);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|