diff --git a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs index deb47e0..513e8d9 100644 --- a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Prices; namespace PyroFetes.Endpoints.Prices; @@ -10,7 +12,7 @@ public class DeletePriceRequest public int SupplierId { get; set; } } -public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint +public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint { public override void Configure() { @@ -20,8 +22,7 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId,req.SupplierId), ct); if (price == null) { @@ -29,9 +30,8 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchPriceEndpoint( + PricesRepository pricesRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +19,8 @@ public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId),ct); + if (price == null) { await Send.NotFoundAsync(ct); @@ -24,14 +28,9 @@ public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint(price), ct); } } \ No newline at end of file