public async Task <IActionResult> SimilarProducts([FromQuery] string description) { // for product forecasting, we only take into consideration // products with more than 8 months of history const int minimalProductSalesHistoryDepth = 8; var products = await catalogService.GetSimilarProductsAsync(description); var productDepths = await orderingService.GetProductHistoryDepthAsync(products.Select(p => p.id)); var productDepthIds = productDepths.Where(p => p.count > minimalProductSalesHistoryDepth).Select(p => p.productId.ToString()); var validProducts = products .Where(p => productDepthIds.Contains(p.id)) .Select(p => new { p.id, p.description, p.price, pictureUri = catalogService.GetProductPicture(p.id) }); return(Ok(validProducts)); }