Refactor all code
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.WarehouseProducts;
|
||||
|
||||
@@ -20,21 +18,20 @@ public class GetTotalQuantityEndpoint(
|
||||
Get("/wareHouseProducts/{@ProductId}", x => new { x.ProductId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
|
||||
{
|
||||
bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId), ct);
|
||||
bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, null), ct);
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
int? totalQuantityNullable = await warehouseProductsRepository.
|
||||
SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
|
||||
|
||||
int totalQuantity = totalQuantityNullable ?? 0;
|
||||
|
||||
int? totalQuantityNullable = await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
|
||||
|
||||
int totalQuantity = totalQuantityNullable ?? 0;
|
||||
|
||||
GetTotalQuantityDto responseDto = new()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user