From ee12986fef895d703652e8ab3e20672308fac035 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Mon, 22 Dec 2025 14:22:16 +0100 Subject: [PATCH] Added query deleting --- .../Controllers/SearchdomainController.cs | 29 +++++++ src/Server/Views/Home/Index.cshtml | 76 +++++++++++++++++-- src/Shared/Models/SearchdomainResults.cs | 9 +++ 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/src/Server/Controllers/SearchdomainController.cs b/src/Server/Controllers/SearchdomainController.cs index 6d75dbf..20f0f2e 100644 --- a/src/Server/Controllers/SearchdomainController.cs +++ b/src/Server/Controllers/SearchdomainController.cs @@ -1,5 +1,6 @@ using System.Text.Json; using ElmahCore; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Server.Exceptions; using Server.Helper; @@ -156,6 +157,34 @@ public class SearchdomainController : ControllerBase return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true }); } + [HttpDelete("Searches")] + public ActionResult DeleteSearch(string searchdomain, string query) + { + Searchdomain searchdomain_; + try + { + searchdomain_ = _domainManager.GetSearchdomain(searchdomain); + } + catch (SearchdomainNotFoundException) + { + _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]); + return Ok(new SearchdomainDeleteSearchResult() { Success = false, Message = "Searchdomain not found" }); + } + catch (Exception ex) + { + _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]); + return Ok(new SearchdomainDeleteSearchResult() { Success = false, Message = ex.Message }); + } + Dictionary searchCache = searchdomain_.searchCache; + bool containsKey = searchCache.ContainsKey(query); + if (containsKey) + { + searchCache.Remove(query); + return Ok(new SearchdomainDeleteSearchResult() {Success = true}); + } + return Ok(new SearchdomainDeleteSearchResult() {Success = false, Message = "Query not found in search cache"}); + } + [HttpGet("GetSettings")] public ActionResult GetSettings(string searchdomain) { diff --git a/src/Server/Views/Home/Index.cshtml b/src/Server/Views/Home/Index.cshtml index 7848b8b..240cd0e 100644 --- a/src/Server/Views/Home/Index.cshtml +++ b/src/Server/Views/Home/Index.cshtml @@ -502,6 +502,33 @@ + + +