From f59c5bd32e44a87ee964f5593ce8ffb37b40bffa Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 23 Jun 2026 06:57:08 -0400 Subject: [PATCH] feat: add GET /drawings/{name}/dxf endpoint to export PEP drawings as DXF --- PepApi.Core/Controllers/DrawingsController.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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