using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SCM.Application.Users; using SCM.Shared.Api; using SCM.Shared.Constants; namespace SCM.Api.Controllers; /// Administração de usuários/perfis (RBAC) — somente Administrador. [ApiController] [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/usuarios")] [Authorize(Roles = Roles.Administrador)] [Produces("application/json")] public sealed class UsuariosController : ControllerBase { private readonly IUserService _service; public UsuariosController(IUserService service) => _service = service; [HttpGet] [ProducesResponseType(typeof(IReadOnlyList), StatusCodes.Status200OK)] public async Task>> GetAll(CancellationToken ct = default) => Ok(await _service.GetAllAsync(ct)); [HttpPost] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)] public async Task> Create([FromBody] CreateUserRequest request, CancellationToken ct = default) => Ok(await _service.CreateAsync(request, ct)); [HttpPut("{id:guid}")] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task> Update(Guid id, [FromBody] UpdateUserRequest request, CancellationToken ct = default) => Ok(await _service.UpdateAsync(id, request, ct)); [HttpPost("{id:guid}/redefinir-senha")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task ResetPassword(Guid id, [FromBody] ResetPasswordRequest request, CancellationToken ct = default) { await _service.ResetPasswordAsync(id, request, ct); return NoContent(); } }