Example #1
0
        public async Task <IActionResult> Search([FromBody] string query)
        {
            TweetResultViewModel viewModel = new TweetResultViewModel();

            if (String.IsNullOrEmpty(query))
            {
                viewModel.Message = "You need to enter a query...";
                return(View("Index", viewModel));
            }
            viewModel.queryInput = query;
            var client          = _client.CreateClient("searchApi");
            var responseMessage = await client.PostAsJsonAsync($"api/Search",
                                                               new QueryModel { query = query });

            if (!responseMessage.IsSuccessStatusCode)
            {
                _logger.LogError(responseMessage.ReasonPhrase);
                viewModel.Message = "Yikes something went wrong. Try again";
            }
            else
            {
                var stringJson = await responseMessage.Content.ReadAsStringAsync();

                List <Tweet> resultTweets = JsonConvert.DeserializeObject <List <Tweet> >(stringJson);
                viewModel.tweetResults = resultTweets.OrderByDescending(x => x.Score).ToList();

                if (!viewModel.tweetResults.Any())
                {
                    viewModel.Message = "No results!";
                }
            }
            return(View("Index", viewModel));
        }
Example #2
0
        public async Task <IActionResult> Index()
        {
            TweetResultViewModel viewModel = new TweetResultViewModel();

            //send warm up message to ensure azure function is on
            // var request = new HttpRequestMessage(HttpMethod.Get, $"api/BuildIndex");
            // var client = _client.CreateClient("searchApi");
            //client.SendAsync(request).Wait();

            return(View(viewModel));
        }