From e8c62f0ef2cdb5f3772ba92203238d6aaf03e9af Mon Sep 17 00:00:00 2001 From: Arunima George Date: Mon, 19 Aug 2024 16:18:31 +0100 Subject: [PATCH 1/4] TD-4486-AutoSuggestionWebLocalBackup --- .../Interfaces/ISearchService.cs | 7 +++ .../Services/SearchService.cs | 26 ++++++++++ .../NavigationItems/Searchbar.cshtml | 1 + .../Controllers/SearchController.cs | 15 ++++++ .../FindwiseCollectionIdSettings.cs | 5 ++ .../ISearchService.cs | 7 +++ .../LearningHub.Nhs.Services/SearchService.cs | 47 +++++++++++++++++++ 7 files changed, 108 insertions(+) diff --git a/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs b/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs index b01be5bce..8a2f0aec1 100644 --- a/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs +++ b/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs @@ -84,5 +84,12 @@ public interface ISearchService /// The catalogue Search Request Model. /// The . Task GetAllCatalogueSearchResultAsync(AllCatalogueSearchRequestModel catalogueSearchRequestModel); + + /// + /// The Get AutoSuggestion List. + /// + /// The term. + /// The . + Task GetAutoSuggestionList(string term); } } diff --git a/LearningHub.Nhs.WebUI/Services/SearchService.cs b/LearningHub.Nhs.WebUI/Services/SearchService.cs index 8e22e0eeb..f8405b199 100644 --- a/LearningHub.Nhs.WebUI/Services/SearchService.cs +++ b/LearningHub.Nhs.WebUI/Services/SearchService.cs @@ -16,6 +16,7 @@ namespace LearningHub.Nhs.WebUI.Services using LearningHub.Nhs.WebUI.Helpers; using LearningHub.Nhs.WebUI.Interfaces; using LearningHub.Nhs.WebUI.Models.Search; + using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; @@ -587,6 +588,31 @@ public async Task CreateCatalogueSearchTermEventAsync(CatalogueSearchReques } } + /// + /// The GetAutoSuggestionList. + /// + /// The term. + /// The auto suggestion list. + public async Task GetAutoSuggestionList(string term) + { + var client = await this.LearningHubHttpClient.GetClientAsync(); + var request = $"Search/GetAutoSuggestionResult/{term}"; + var response = await client.GetAsync(request).ConfigureAwait(false); + + var viewModel = new AutoSuggestionModel(); + if (response.IsSuccessStatusCode) + { + var result = response.Content.ReadAsStringAsync().Result; + viewModel = JsonConvert.DeserializeObject(result); + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + throw new Exception("AccessDenied"); + } + + return viewModel; + } + /// /// GetAllCatalogueSearchResultAsync. /// diff --git a/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml b/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml index 139488831..c325c0f5a 100644 --- a/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml @@ -17,6 +17,7 @@ - \ No newline at end of file + + + + \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml b/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml index c325c0f5a..2ae4c0d7d 100644 --- a/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml @@ -19,6 +19,7 @@ @* *@ +