From 9e6834754f50cd9710999f3b18c1a999b39c76c6 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sun, 30 Nov 2025 14:23:30 +0100 Subject: [PATCH] added DeleteDeliveryNoteEndpoint.cs --- .../DeleteDeliveryNoteEndpoint.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 PyroFetes/Endpoints/DeliveryNotes/DeleteDeliveryNoteEndpoint.cs diff --git a/PyroFetes/Endpoints/DeliveryNotes/DeleteDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/DeleteDeliveryNoteEndpoint.cs new file mode 100644 index 0000000..4fe7644 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/DeleteDeliveryNoteEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using PyroFetes.Endpoints.Quotations; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.DeliveryNotes; +using PyroFetes.Specifications.Quotations; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class DeleteDeliveryNoteRequest +{ + public int Id { get; set; } +} + +public class DeleteDeliveryNoteEndpoint( + DeliveryNotesRepository deliveryNotesRepository) : Endpoint +{ + public override void Configure() + { + Delete("/deliveryNotes/{@Id}", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(DeleteDeliveryNoteRequest req, CancellationToken ct) + { + DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct); + + if (deliveryNote == null) + { + await Send.NotFoundAsync(ct); + return; + } + + await deliveryNotesRepository.DeleteAsync(deliveryNote, ct); + + await Send.NoContentAsync(ct); + } +} \ No newline at end of file