dde4c68b2f
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 2m33s
- Add GetLowStockItemsResponseDto and LowStockItemDto for low stock item queries. - Create CreateStockMovementCommand and its handler for managing stock movements. - Implement CreateStockMovementCommandValidator for validating stock movement commands. - Add GetStockMovementsQuery and its handler to retrieve stock movement records. - Create GetStockMovementsResponseDto and StockMovementListDto for stock movement responses. - Implement GetStockMovementsByInventoryItemQuery and its handler for fetching movements by inventory item. - Add CreateWarehouseCommand and its handler for creating new warehouses. - Implement CreateWarehouseCommandValidator for warehouse creation validation. - Add DeleteWarehouseCommand and its handler for removing warehouses. - Implement SetDefaultWarehouseCommand and its handler for setting a default warehouse. - Create UpdateWarehouseCommand and its handler for updating warehouse details. - Implement GetAllWarehousesQuery and its handler to retrieve all warehouses. - Add GetWarehouseQuery and its handler for fetching a specific warehouse by ID. - Implement SearchWarehousesQuery and its handler for searching warehouses based on criteria.
54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
namespace CMSMicroservice.Application.InventoryItemCQ.Queries.GetLowStockItems;
|
|
|
|
public class GetLowStockItemsQueryHandler : IRequestHandler<GetLowStockItemsQuery, GetLowStockItemsResponseDto>
|
|
{
|
|
private readonly IApplicationDbContext _context;
|
|
|
|
public GetLowStockItemsQueryHandler(IApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<GetLowStockItemsResponseDto> Handle(GetLowStockItemsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var query = _context.InventoryItems
|
|
.AsNoTracking()
|
|
.Include(i => i.Warehouse)
|
|
.Include(i => i.Product)
|
|
.Include(i => i.DiscountProduct)
|
|
.Where(i => i.Quantity <= i.LowStockThreshold);
|
|
|
|
if (request.WarehouseId.HasValue)
|
|
{
|
|
query = query.Where(i => i.WarehouseId == request.WarehouseId.Value);
|
|
}
|
|
|
|
var totalCount = await query.CountAsync(cancellationToken);
|
|
|
|
var items = await query
|
|
.OrderBy(i => i.AvailableQuantity)
|
|
.Take(request.Count)
|
|
.Select(i => new LowStockItemDto
|
|
{
|
|
Id = i.Id,
|
|
ProductId = i.ProductId,
|
|
DiscountProductId = i.DiscountProductId,
|
|
ProductType = i.ProductType,
|
|
WarehouseId = i.WarehouseId,
|
|
WarehouseName = i.Warehouse != null ? i.Warehouse.Name : null,
|
|
ProductTitle = i.Product != null ? i.Product.Title : (i.DiscountProduct != null ? i.DiscountProduct.Title : null),
|
|
Quantity = i.Quantity,
|
|
ReservedQuantity = i.ReservedQuantity,
|
|
AvailableQuantity = i.AvailableQuantity,
|
|
LowStockThreshold = i.LowStockThreshold
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return new GetLowStockItemsResponseDto
|
|
{
|
|
Items = items,
|
|
TotalCount = totalCount
|
|
};
|
|
}
|
|
}
|