scm-api / src /SCM.Api /Controllers /RelatoriosPdfController.cs
rafaeldavila's picture
Deploy SCM API (.NET 8) - Docker Space
de8b914 verified
Raw History Blame Contribute Delete
2.75 kB
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SCM.Application.Controle;
using SCM.Application.Medicao;
using SCM.Application.Qualidade;
using SCM.Application.Relatorios;
using SCM.Shared.Api;
namespace SCM.Api.Controllers;
/// <summary>Geração de PDFs dos relatórios (faturamento, acompanhamento, relatório técnico).</summary>
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}")]
[Authorize]
public sealed class RelatoriosPdfController : ControllerBase
{
private readonly IPdfReportService _pdf;
public RelatoriosPdfController(IPdfReportService pdf) => _pdf = pdf;
/// <summary>PDF do faturamento por EAP do contrato.</summary>
[HttpGet("contratos/{contratoId:guid}/faturamento/pdf")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<IActionResult> FaturamentoPdf(
Guid contratoId, [FromServices] IFaturamentoService faturamento, CancellationToken ct = default)
{
var dados = await faturamento.GetFaturamentoAsync(contratoId, ct);
var bytes = _pdf.Faturamento(dados);
return File(bytes, "application/pdf", $"faturamento-{contratoId}.pdf");
}
/// <summary>PDF do resumo de acompanhamento da obra na data.</summary>
[HttpGet("obras/{obraId:guid}/acompanhamento/pdf")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<IActionResult> AcompanhamentoPdf(
Guid obraId, [FromQuery] DateOnly data,
[FromServices] IAcompanhamentoService acompanhamento, CancellationToken ct = default)
{
var foto = await acompanhamento.GetFotoAsync(obraId, data, ct);
var historico = await acompanhamento.GetHistoricoAsync(obraId, ct);
var bytes = _pdf.Acompanhamento(foto, historico);
return File(bytes, "application/pdf", $"acompanhamento-{obraId}.pdf");
}
/// <summary>PDF de um relatório técnico.</summary>
[HttpGet("relatorios-tecnicos/{id:guid}/pdf")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public async Task<IActionResult> RelatorioTecnicoPdf(
Guid id, [FromServices] IRelatorioTecnicoService relatorios, CancellationToken ct = default)
{
// GetByProducao/GetByObra retornam listas; aqui buscamos o RT específico pela obra dele.
var rt = await relatorios.GetByIdAsync(id, ct);
var bytes = _pdf.RelatorioTecnico(rt);
return File(bytes, "application/pdf", $"relatorio-tecnico-{rt.Numero}.pdf");
}
}