From 63c6044c1d12ab162cf37731a310561101376f35 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Wed, 1 May 2024 21:29:16 +0200 Subject: [PATCH] Add option to view profile from search result. Fixes #4 --- Client/Components/Pages/Search.razor | 12 ++++++++++++ Server/Api/DataController.cs | 25 +++++++++++++++++++++++++ Server/Api/ReplayController.cs | 4 +++- Shared/SearchResult.cs | 2 ++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Client/Components/Pages/Search.razor b/Client/Components/Pages/Search.razor index d6d6ef4..c753cbf 100644 --- a/Client/Components/Pages/Search.razor +++ b/Client/Components/Pages/Search.razor @@ -52,6 +52,11 @@ {

Found @SearchResult.TotalReplays replays in @stopWatch.ElapsedMilliseconds ms

} + + if (ProfileFound != null) + { +

Profile found for @ProfileFound.Username, click here to view

+ }

Page @pageDisplay of @SearchResult.PageCount

@@ -99,6 +104,7 @@ public string? ErrorMessage { get; set; } public string? ErrorDetails { get; set; } public Stopwatch stopWatch { get; set; } = new Stopwatch(); + public PlayerData? ProfileFound { get; set; } public SearchResult SearchResult { get; set; } = new SearchResult(); @@ -136,6 +142,12 @@ stopWatch.Stop(); return; } + + if (loadedReplays.SearchMode is SearchMode.PlayerOocName) + { + var playerGuid = await Http.GetAsync("/api/Data/has-profile?username=" + loadedReplays.Query); + ProfileFound = await playerGuid.Content.ReadFromJsonAsync(); + } SearchResult = loadedReplays; stopWatch.Stop(); diff --git a/Server/Api/DataController.cs b/Server/Api/DataController.cs index c420df6..40c0435 100644 --- a/Server/Api/DataController.cs +++ b/Server/Api/DataController.cs @@ -192,6 +192,31 @@ [FromQuery] string username return Ok(completions); } + /// + /// Tries to find a player with the given username. If found, returns the player's GUID. + /// + [HttpGet] + [Route("has-profile")] + public async Task HasProfile( + [FromQuery] string username + ) + { + var player = await _context.Players + .FirstOrDefaultAsync(p => p.PlayerOocName.ToLower() == username.ToLower()); + if (player == null) + return new PlayerData() + { + PlayerGuid = Guid.Empty, + Username = "NOT FOUND" + }; + + return new PlayerData() + { + PlayerGuid = player.PlayerGuid, + Username = player.PlayerOocName + }; + } + [HttpGet] [Route("leaderboard")] public async Task GetLeaderboard( diff --git a/Server/Api/ReplayController.cs b/Server/Api/ReplayController.cs index 7837cb5..39af901 100644 --- a/Server/Api/ReplayController.cs +++ b/Server/Api/ReplayController.cs @@ -109,7 +109,9 @@ public async Task SearchReplays( PageCount = pageCount, CurrentPage = page, TotalReplays = found.Item2, - IsCache = found.Item3 + IsCache = found.Item3, + SearchMode = searchMode, + Query = query }); } diff --git a/Shared/SearchResult.cs b/Shared/SearchResult.cs index a2e61f5..0b38124 100644 --- a/Shared/SearchResult.cs +++ b/Shared/SearchResult.cs @@ -12,4 +12,6 @@ public class SearchResult public int CurrentPage { get; set; } = 1; public List Replays { get; set; } = new(); public int TotalReplays { get; set; } = 0; + public SearchMode SearchMode { get; set; } + public string Query { get; set; } = ""; } \ No newline at end of file