public IActionResult GetMenuItemsByIds([FromQuery] GetMenuItemsByIdsRequest request) { if (request is null) { return(BadRequest()); } return(Ok(_pizzaStoreService.GetMenuItemsByIds(request))); }
public List <Business.MenuItem> GetMenuItemsByIds(GetMenuItemsByIdsRequest request) { if (request is null || request.MenuItemIds is null || request.MenuItemIds.Count <= 0) { return(new List <Business.MenuItem>()); } List <Func <QueryContainerDescriptor <Entity.MenuItem>, QueryContainer> > shouldQueries = new List <Func <QueryContainerDescriptor <Entity.MenuItem>, QueryContainer> >(); request.MenuItemIds.ForEach(id => { shouldQueries.Add(s => s.Match(m => m.Field(f => f.Id).Query(id))); }); var searchResponse = _elasticClient.Search <Entity.MenuItem>(s => s.Index(_configuration["MenuIndexName"]) .Query(q => q.Bool(bq => bq.Should(shouldQueries)) )); List <Business.MenuItem> menuItems = searchResponse?.Documents?.MapTo <List <Business.MenuItem> >() ?? new List <Business.MenuItem>(); return(menuItems); }