Refactor all code
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.WarehouseProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||
|
||||
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
|
||||
: Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository warehouseProductsRepository) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -17,25 +17,17 @@ public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
|
||||
|
||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
WarehouseProduct? wareHouseProduct =
|
||||
await database.WarehouseProducts.SingleOrDefaultAsync(
|
||||
wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
|
||||
|
||||
if (wareHouseProduct == null)
|
||||
WarehouseProduct? wareHouseProduct = await warehouseProductsRepository.FirstOrDefaultAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, req.WareHouseId) , ct);
|
||||
|
||||
if (wareHouseProduct is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
wareHouseProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetWareHouseProductDto responseDto = new()
|
||||
{
|
||||
ProductId = wareHouseProduct.ProductId,
|
||||
WareHouseId = wareHouseProduct.WarehouseId,
|
||||
Quantity = wareHouseProduct.Quantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await warehouseProductsRepository.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user