feat: add GET /drawings/{name}/dxf endpoint to export PEP drawings as DXF
This commit is contained in:
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PepApi.Core.Models;
|
using PepApi.Core.Models;
|
||||||
using PepLib.Data;
|
using PepLib.Data;
|
||||||
|
using PepLib.IO;
|
||||||
|
|
||||||
namespace PepApi.Core.Controllers;
|
namespace PepApi.Core.Controllers;
|
||||||
|
|
||||||
@@ -147,6 +148,38 @@ public class DrawingsController : ControllerBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Export a drawing as a DXF file.
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("{name}/dxf")]
|
||||||
|
public async Task<IActionResult> GetDrawingDxf(string name)
|
||||||
|
{
|
||||||
|
var drawing = await _db.Drawings
|
||||||
|
.Where(d => d.Name.ToUpper() == name.ToUpper())
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (drawing == null)
|
||||||
|
return NotFound(new { message = "Drawing not found in database" });
|
||||||
|
|
||||||
|
var filePath = drawing.Path + drawing.File;
|
||||||
|
|
||||||
|
if (!System.IO.File.Exists(filePath))
|
||||||
|
return NotFound(new { message = "Drawing file not found on disk" });
|
||||||
|
|
||||||
|
PepLib.Models.Drawing pep;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pep = PepLib.Models.Drawing.Load(filePath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, new { message = $"Failed to load drawing: {ex.Message}" });
|
||||||
|
}
|
||||||
|
|
||||||
|
var stream = DrawingDxfExporter.Export(pep);
|
||||||
|
return File(stream, "application/dxf", $"{name}.dxf");
|
||||||
|
}
|
||||||
|
|
||||||
private static DrawingDetails ConvertToDetails(Drawing drawing)
|
private static DrawingDetails ConvertToDetails(Drawing drawing)
|
||||||
{
|
{
|
||||||
return new DrawingDetails
|
return new DrawingDetails
|
||||||
|
|||||||
Reference in New Issue
Block a user