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