Adapted Price Endpoints

This commit is contained in:
Cristiano
2025-11-13 16:31:00 +01:00
parent c6d4ef2c58
commit ae834d1e3c
12 changed files with 139 additions and 106 deletions

View File

@@ -0,0 +1,36 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.QuotationProduct;
public class DeletePriceRequest
{
public int ProductId { get; set; }
public int SupplierId { get; set; }
}
public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint<DeletePriceRequest>
{
public override void Configure()
{
Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
AllowAnonymous();
}
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct)
{
var price = await database.Prices
.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct);
if (price == null)
{
await Send.NotFoundAsync(ct);
return;
}
database.Prices.Remove(price);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}