using BackOffice.BFF.Application.InventoryCQ.Queries.GetAllInventoryItems; using CMSMicroservice.Protobuf.Protos.Inventory; namespace BackOffice.BFF.Application.InventoryCQ.Queries.GetLowStockItems; public class GetLowStockItemsQueryHandler : IRequestHandler { private readonly IApplicationContractContext _context; public GetLowStockItemsQueryHandler(IApplicationContractContext context) { _context = context; } public async Task Handle(GetLowStockItemsQuery request, CancellationToken cancellationToken) { var protoRequest = new GetLowStockItemsRequest { Page = request.Page, PageSize = request.PageSize }; if (request.WarehouseId.HasValue) protoRequest.WarehouseId = request.WarehouseId.Value; if (request.ProductType.HasValue) protoRequest.ProductType = (ProductType)request.ProductType.Value; var response = await _context.Inventory.GetLowStockItemsAsync(protoRequest, cancellationToken: cancellationToken); return new GetLowStockItemsResponseDto { TotalCount = response.TotalCount, Items = response.Items.Select(i => new GetAllInventoryItems.InventoryItemDto { Id = i.Id, ProductId = i.ProductId, DiscountProductId = i.DiscountProductId, ProductType = (int)i.ProductType, ProductTitle = i.ProductTitle, ProductPrice = i.ProductPrice, Quantity = i.Quantity, ReservedQuantity = i.ReservedQuantity, AvailableQuantity = i.AvailableQuantity, LowStockThreshold = i.LowStockThreshold, ReorderPoint = i.ReorderPoint, MaxStockLevel = i.MaxStockLevel, WarehouseId = i.WarehouseId, WarehouseName = i.WarehouseName, IsLowStock = true }).ToList() }; } }