forked from sanchezvem/pyrofetes-backend
Added new endpoint to manage warehouse
This commit is contained in:
@@ -3,11 +3,12 @@ using PyroFetes.DTO.WareHouseProduct.Request;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.WareHouse;
|
||||
using PyroFetes.Specifications.WarehouseProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||
|
||||
public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository warehouseProductsRepository) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository warehouseProductsRepository, WareHouseRepository wareHouseRepository , AutoMapper.IMapper mapper) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -18,16 +19,21 @@ public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository w
|
||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
WarehouseProduct? wareHouseProduct = await warehouseProductsRepository.FirstOrDefaultAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, req.WareHouseId), ct);
|
||||
Warehouse? warehouse = await wareHouseRepository.SingleOrDefaultAsync(new GetWareHouseByIdSpec(req.WareHouseId), ct);
|
||||
|
||||
if (wareHouseProduct is null)
|
||||
if (warehouse is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
wareHouseProduct.Quantity = req.Quantity;
|
||||
await warehouseProductsRepository.SaveChangesAsync(ct);
|
||||
|
||||
|
||||
if (wareHouseProduct is null) await warehouseProductsRepository.AddAsync(mapper.Map<WarehouseProduct>(req), ct);
|
||||
else
|
||||
{
|
||||
wareHouseProduct.Quantity = req.Quantity;
|
||||
await warehouseProductsRepository.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user