75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using line_gestao_api.Dtos;
|
|
using line_gestao_api.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace line_gestao_api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/mve-audit")]
|
|
[Authorize(Roles = "sysadmin,gestor")]
|
|
public class MveAuditController : ControllerBase
|
|
{
|
|
private readonly MveAuditService _mveAuditService;
|
|
|
|
public MveAuditController(MveAuditService mveAuditService)
|
|
{
|
|
_mveAuditService = mveAuditService;
|
|
}
|
|
|
|
public sealed class MveAuditUploadForm
|
|
{
|
|
public IFormFile File { get; set; } = default!;
|
|
}
|
|
|
|
[HttpPost("preview")]
|
|
[Consumes("multipart/form-data")]
|
|
[RequestSizeLimit(20_000_000)]
|
|
public async Task<ActionResult<MveAuditRunDto>> Preview(
|
|
[FromForm] MveAuditUploadForm form,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
var result = await _mveAuditService.CreateRunAsync(form.File, cancellationToken);
|
|
return Ok(result);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
return BadRequest(new { message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<ActionResult<MveAuditRunDto>> GetById(Guid id, CancellationToken cancellationToken)
|
|
{
|
|
var result = await _mveAuditService.GetByIdAsync(id, cancellationToken);
|
|
return result == null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpGet("latest")]
|
|
public async Task<ActionResult<MveAuditRunDto>> GetLatest(CancellationToken cancellationToken)
|
|
{
|
|
var result = await _mveAuditService.GetLatestAsync(cancellationToken);
|
|
return result == null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpPost("{id:guid}/apply")]
|
|
public async Task<ActionResult<ApplyMveAuditResultDto>> Apply(
|
|
Guid id,
|
|
[FromBody] ApplyMveAuditRequestDto request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
var result = await _mveAuditService.ApplyAsync(id, request?.IssueIds, cancellationToken);
|
|
return result == null ? NotFound() : Ok(result);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
return BadRequest(new { message = ex.Message });
|
|
}
|
|
}
|
|
}
|