public async Task <IActionResult> Get(string query) { var products = new List <Product>(); try { var entities = await _entityAnalysisService.GetEntitiesAsync(query, MaxEntitiesCount); var stringEntities = entities.Select(entity => entity.Name); var associations = await _associationService.GetAssociationsAsync(stringEntities, MaxEntitiesCount); foreach (var association in associations) { foreach (var item in association.Items) { products.AddRange(_productService.SearchProducts(item.Item) .Where(product => product.ImageUrl != null) .Take(3) .ToList()); } } } catch (AssociationServiceException ex) { return(ReturnServiceUnavailableResult(ex)); } catch (ProductServiceException ex) { return(ReturnServiceUnavailableResult(ex)); } catch (EntityAnalysisServiceException ex) { return(ReturnServiceUnavailableResult(ex)); } return(Ok(products)); }
public async Task <ActionResult <ProductAssociation[]> > GetAllAssociations(string productId) { var result = await _associationService.GetAssociationsAsync(new string[] { productId }); return(Ok(result)); }