Spaces:
Runtime error
Runtime error
Download src/SCM.Api/Controllers/OcorrenciasAtividadeController.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 5.3 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Api/Controllers/OcorrenciasAtividadeController.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Api/Controllers/OcorrenciasAtividadeController.cs
-
curl -L -o OcorrenciasAtividadeController.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Api/Controllers/OcorrenciasAtividadeController.cs
5.3 kB
| using System.Security.Claims; | |
| using Asp.Versioning; | |
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| using SCM.Application.AtividadesCiclicas; | |
| using SCM.Domain.AtividadesCiclicas; | |
| using SCM.Shared.Api; | |
| using SCM.Shared.Constants; | |
| using SCM.Shared.Exceptions; | |
| namespace SCM.Api.Controllers; | |
| /// <summary> | |
| /// Ocorrências de atividade cíclica: "Minhas Atividades" (visíveis ao grupo do usuário; perfis | |
| /// administrativos veem tudo), conclusão, evidências (upload/download) e indicadores. | |
| /// </summary> | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| public sealed class OcorrenciasAtividadeController : ControllerBase | |
| { | |
| private readonly IOcorrenciaAtividadeService _service; | |
| public OcorrenciasAtividadeController(IOcorrenciaAtividadeService service) => _service = service; | |
| private Guid UsuarioAtualId() | |
| { | |
| var raw = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub"); | |
| return Guid.TryParse(raw, out var id) ? id : throw new UnauthorizedAccessException("Usuário não identificado."); | |
| } | |
| /// <summary>Perfis administrativos veem todas as ocorrências; demais, só as do seu grupo.</summary> | |
| private bool VerTudo() => User.IsInRole(Roles.Administrador) || User.IsInRole(Roles.Gestor); | |
| [] | |
| [] | |
| public async Task<ActionResult<IReadOnlyList<OcorrenciaResponse>>> Listar( | |
| [] Guid? obraId = null, [FromQuery] Guid? grupoTrabalhoId = null, [FromQuery] StatusOcorrencia? status = null, | |
| [] Guid? itemControleId = null, [FromQuery] DateOnly? de = null, [FromQuery] DateOnly? ate = null, | |
| CancellationToken ct = default) | |
| { | |
| var filtro = new OcorrenciaFiltro(obraId, grupoTrabalhoId, status, itemControleId, de, ate); | |
| return Ok(await _service.QueryAsync(filtro, UsuarioAtualId(), VerTudo(), ct)); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<OcorrenciaResponse>> GetById(Guid id, CancellationToken ct = default) | |
| => Ok(await _service.GetByIdAsync(id, ct)); | |
| [] | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<OcorrenciaResponse>> Concluir(Guid id, [FromBody] ConcluirOcorrenciaRequest request, CancellationToken ct = default) | |
| => Ok(await _service.ConcluirAsync(id, request, UsuarioAtualId(), ct)); | |
| [] | |
| [] | |
| public async Task<ActionResult<IndicadoresResponse>> Indicadores([FromQuery] Guid? obraId = null, CancellationToken ct = default) | |
| => Ok(await _service.IndicadoresAsync(obraId, UsuarioAtualId(), VerTudo(), ct)); | |
| // --- evidências (bytea) --- | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| public async Task<ActionResult<EvidenciaResponse>> Upload(Guid id, IFormFile arquivo, CancellationToken ct = default) | |
| { | |
| if (arquivo is null || arquivo.Length == 0) | |
| throw new DomainException("O arquivo é obrigatório."); | |
| using var ms = new MemoryStream(); | |
| await arquivo.CopyToAsync(ms, ct); | |
| var evidencia = await _service.AdicionarEvidenciaAsync(id, arquivo.FileName, arquivo.ContentType, ms.ToArray(), ct); | |
| return CreatedAtAction(nameof(Evidencias), new { id, version = "1.0" }, evidencia); | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<IReadOnlyList<EvidenciaResponse>>> Evidencias(Guid id, CancellationToken ct = default) | |
| => Ok(await _service.ListarEvidenciasAsync(id, ct)); | |
| [] | |
| [] | |
| [] | |
| public async Task<IActionResult> Download(Guid evidenciaId, CancellationToken ct = default) | |
| { | |
| var e = await _service.BaixarEvidenciaAsync(evidenciaId, ct); | |
| return File(e.Conteudo, e.TipoConteudo, e.NomeArquivo); | |
| } | |
| [] | |
| [] | |
| [] | |
| public async Task<IActionResult> RemoverEvidencia(Guid evidenciaId, CancellationToken ct = default) | |
| { | |
| await _service.RemoverEvidenciaAsync(evidenciaId, ct); | |
| return NoContent(); | |
| } | |
| } | |