Spaces:
Runtime error
Runtime error
File size: 6,171 Bytes
de8b914 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SCM.Application.Planejamento;
using SCM.Application.Planejamento.Dtos;
using SCM.Shared.Api;
using SCM.Shared.Constants;
namespace SCM.Api.Controllers;
/// <summary>Folhas de Tarefa (MPL) — programação semanal de equipes por contrato.</summary>
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/folhas-tarefa")]
[Authorize]
[Produces("application/json")]
public sealed class FolhasTarefaController : ControllerBase
{
private readonly IFolhaTarefaService _service;
public FolhasTarefaController(IFolhaTarefaService service) => _service = service;
/// <summary>Lista as FTs de um contrato (ordenadas por código).</summary>
[HttpGet]
[ProducesResponseType(typeof(IReadOnlyList<FolhaTarefaResponse>), StatusCodes.Status200OK)]
public async Task<ActionResult<IReadOnlyList<FolhaTarefaResponse>>> GetByContrato(
[FromQuery] Guid contratoId, CancellationToken ct = default)
=> Ok(await _service.GetByContratoAsync(contratoId, ct));
/// <summary>Obtém uma FT pelo identificador.</summary>
[HttpGet("{id:guid}")]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<ActionResult<FolhaTarefaResponse>> GetById(Guid id, CancellationToken ct = default)
=> Ok(await _service.GetByIdAsync(id, ct));
/// <summary>Cria uma FT (código único por contrato; nasce EM_PROGRAMACAO).</summary>
[HttpPost]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)]
public async Task<ActionResult<FolhaTarefaResponse>> Create(
[FromBody] CreateFolhaTarefaRequest request, CancellationToken ct = default)
{
var created = await _service.CreateAsync(request, ct);
return CreatedAtAction(nameof(GetById), new { id = created.Id, version = "1.0" }, created);
}
/// <summary>Altera uma FT em programação (contrato/equipe/supervisor imutáveis).</summary>
[HttpPut("{id:guid}")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)]
public async Task<ActionResult<FolhaTarefaResponse>> Update(
Guid id, [FromBody] UpdateFolhaTarefaRequest request, CancellationToken ct = default)
=> Ok(await _service.UpdateAsync(id, request, ct));
/// <summary>Fecha (programa) a FT: EM_PROGRAMACAO → PROGRAMADA, congelando a equipe.</summary>
[HttpPost("{id:guid}/fechar")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<ActionResult<FolhaTarefaResponse>> Fechar(Guid id, CancellationToken ct = default)
=> Ok(await _service.FecharAsync(id, ct));
/// <summary>Reabre a programação: PROGRAMADA → EM_PROGRAMACAO (descongela sem produção/HH).</summary>
[HttpPost("{id:guid}/reabrir-programacao")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<ActionResult<FolhaTarefaResponse>> ReabrirProgramacao(Guid id, CancellationToken ct = default)
=> Ok(await _service.ReabrirProgramacaoAsync(id, ct));
/// <summary>Finaliza a FT: PROGRAMADA → FINALIZADA.</summary>
[HttpPost("{id:guid}/finalizar")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<ActionResult<FolhaTarefaResponse>> Finalizar(Guid id, CancellationToken ct = default)
=> Ok(await _service.FinalizarAsync(id, ct));
/// <summary>Reabre uma FT finalizada: FINALIZADA → PROGRAMADA.</summary>
[HttpPost("{id:guid}/reabrir")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(FolhaTarefaResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<ActionResult<FolhaTarefaResponse>> Reabrir(Guid id, CancellationToken ct = default)
=> Ok(await _service.ReabrirAsync(id, ct));
/// <summary>Exclui uma FT (bloqueado se finalizada).</summary>
[HttpDelete("{id:guid}")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)]
public async Task<IActionResult> Delete(Guid id, CancellationToken ct = default)
{
await _service.DeleteAsync(id, ct);
return NoContent();
}
}
|