diff --git a/PepApi.Core/Controllers/DrawingsController.cs b/PepApi.Core/Controllers/DrawingsController.cs
index 5b86520..e330461 100644
--- a/PepApi.Core/Controllers/DrawingsController.cs
+++ b/PepApi.Core/Controllers/DrawingsController.cs
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PepApi.Core.Models;
using PepLib.Data;
+using PepLib.IO;
namespace PepApi.Core.Controllers;
@@ -147,6 +148,38 @@ public class DrawingsController : ControllerBase
});
}
+ ///
+ /// Export a drawing as a DXF file.
+ ///
+ [HttpGet("{name}/dxf")]
+ public async Task 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)
{
return new DrawingDetails