This commit is contained in:
2025-10-16 19:32:31 +01:00
parent b4502ae562
commit 791eff9256
3 changed files with 38 additions and 10 deletions

View File

@@ -5,8 +5,7 @@ using PyroFetes.DTO.PurchaseProduct.Response;
namespace PyroFetes.Endpoints.PurchaseProduct; namespace PyroFetes.Endpoints.PurchaseProduct;
public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
: Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
{ {
public override void Configure() public override void Configure()
{ {

View File

@@ -1,6 +1,41 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.PurchaseProduct; namespace PyroFetes.Endpoints.PurchaseProduct;
public class DeletePurchaseProductEndpoint public class DeletePurchaseOrderRequest
{ {
public int Id { get; set; }
}
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
{
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);
}
} }

View File

@@ -1,6 +0,0 @@
namespace PyroFetes.Endpoints.PurchaseProduct;
public class UpdatePurchaseProductEndpoint
{
}