From 791eff92562b76d61869292d255800cb58c967b3 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 19:32:31 +0100 Subject: [PATCH] added --- .../CreatePurchaseProductEndpoint.cs | 3 +- .../DeletePurchaseProductEndpoint.cs | 39 ++++++++++++++++++- .../UpdatePurchaseProductEndpoint.cs | 6 --- 3 files changed, 38 insertions(+), 10 deletions(-) delete mode 100644 PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs index 0578342..f060c3a 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs @@ -5,8 +5,7 @@ using PyroFetes.DTO.PurchaseProduct.Response; namespace PyroFetes.Endpoints.PurchaseProduct; -public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) - : Endpoint +public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint { public override void Configure() { diff --git a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs index 1f532ff..7af1030 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs @@ -1,6 +1,41 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; + namespace PyroFetes.Endpoints.PurchaseProduct; -public class DeletePurchaseProductEndpoint +public class DeletePurchaseOrderRequest { - + public int Id { get; set; } +} + +public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Delete("/api/purchaseOrders/{Id:int}"); + AllowAnonymous(); + } + + public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct) + { + var purchaseOrder = await database.PurchaseOrders + .Include(po => po.PurchaseProducts) + .SingleOrDefaultAsync(po => po.Id == req.Id, ct); + + if (purchaseOrder == null) + { + await Send.NotFoundAsync(ct); + return; + } + + if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any()) + { + database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts); + } + + database.PurchaseOrders.Remove(purchaseOrder); + await database.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs deleted file mode 100644 index 3373ae9..0000000 --- a/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PyroFetes.Endpoints.PurchaseProduct; - -public class UpdatePurchaseProductEndpoint -{ - -} \ No newline at end of file