87 lines
2.3 KiB
C#
87 lines
2.3 KiB
C#
using line_gestao_api.Data;
|
|
using line_gestao_api.Dtos;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace line_gestao_api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/import-audit")]
|
|
[Authorize]
|
|
public class ImportAuditController : ControllerBase
|
|
{
|
|
private readonly AppDbContext _db;
|
|
|
|
public ImportAuditController(AppDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
[HttpGet("latest")]
|
|
public async Task<ActionResult<ImportAuditRunDto>> GetLatest()
|
|
{
|
|
var run = await _db.ImportAuditRuns
|
|
.AsNoTracking()
|
|
.Include(x => x.Issues)
|
|
.OrderByDescending(x => x.ImportedAt)
|
|
.ThenByDescending(x => x.Id)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (run == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return Ok(ToDto(run));
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<ActionResult<ImportAuditRunDto>> GetById(Guid id)
|
|
{
|
|
var run = await _db.ImportAuditRuns
|
|
.AsNoTracking()
|
|
.Include(x => x.Issues)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (run == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return Ok(ToDto(run));
|
|
}
|
|
|
|
private static ImportAuditRunDto ToDto(Models.ImportAuditRun run)
|
|
{
|
|
var issues = run.Issues
|
|
.OrderBy(x => x.CreatedAt)
|
|
.ThenBy(x => x.Entity)
|
|
.Select(x => new ImportAuditIssueDto
|
|
{
|
|
Id = x.Id,
|
|
Entity = x.Entity,
|
|
FieldName = x.FieldName,
|
|
SourceValue = x.SourceValue,
|
|
CanonicalValue = x.CanonicalValue,
|
|
Resolution = x.Resolution,
|
|
Severity = x.Severity,
|
|
CreatedAt = x.CreatedAt
|
|
})
|
|
.ToList();
|
|
|
|
return new ImportAuditRunDto
|
|
{
|
|
Id = run.Id,
|
|
ImportedAt = run.ImportedAt,
|
|
FileName = run.FileName,
|
|
Status = run.Status,
|
|
CanonicalTotalLinhas = run.CanonicalTotalLinhas,
|
|
SourceMaxItemGeral = run.SourceMaxItemGeral,
|
|
SourceValidCountGeral = run.SourceValidCountGeral,
|
|
IssueCount = issues.Count,
|
|
Issues = issues
|
|
};
|
|
}
|
|
}
|