Spaces:
Runtime error
Runtime error
File size: 3,526 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 | using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SCM.Application.Qualidade;
using SCM.Application.Qualidade.Dtos;
using SCM.Shared.Api;
using SCM.Shared.Constants;
namespace SCM.Api.Controllers;
/// <summary>Campos de inspeção (estrutura dos dados coletados por sub-atividade padrão).</summary>
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/campos-inspecao")]
[Authorize]
[Produces("application/json")]
public sealed class CamposInspecaoController : ControllerBase
{
private readonly ICampoInspecaoService _service;
public CamposInspecaoController(ICampoInspecaoService service) => _service = service;
/// <summary>Lista os campos de uma sub-atividade padrão (ordenados por ordem/nome).</summary>
[HttpGet]
[ProducesResponseType(typeof(IReadOnlyList<CampoInspecaoResponse>), StatusCodes.Status200OK)]
public async Task<ActionResult<IReadOnlyList<CampoInspecaoResponse>>> GetBySubAtividade(
[FromQuery] Guid subAtividadePadraoId, CancellationToken ct = default)
=> Ok(await _service.GetBySubAtividadeAsync(subAtividadePadraoId, ct));
/// <summary>Obtém um campo pelo identificador.</summary>
[HttpGet("{id:guid}")]
[ProducesResponseType(typeof(CampoInspecaoResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<ActionResult<CampoInspecaoResponse>> GetById(Guid id, CancellationToken ct = default)
=> Ok(await _service.GetByIdAsync(id, ct));
/// <summary>Cria um campo de inspeção.</summary>
[HttpPost]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(CampoInspecaoResponse), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)]
public async Task<ActionResult<CampoInspecaoResponse>> Create(
[FromBody] CreateCampoInspecaoRequest 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 um campo de inspeção (a sub-atividade é imutável).</summary>
[HttpPut("{id:guid}")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor + "," + Roles.Engenheiro)]
[ProducesResponseType(typeof(CampoInspecaoResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)]
public async Task<ActionResult<CampoInspecaoResponse>> Update(
Guid id, [FromBody] UpdateCampoInspecaoRequest request, CancellationToken ct = default)
=> Ok(await _service.UpdateAsync(id, request, ct));
/// <summary>Exclui um campo de inspeção.</summary>
[HttpDelete("{id:guid}")]
[Authorize(Roles = Roles.Administrador + "," + Roles.Gestor)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<IActionResult> Delete(Guid id, CancellationToken ct = default)
{
await _service.DeleteAsync(id, ct);
return NoContent();
}
}
|