Skip to content

Commit

Permalink
Add option to view profile from search result.
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
Simyon264 committed May 1, 2024
1 parent 3af7fa7 commit 63c6044
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Client/Components/Pages/Search.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
{
<p>Found @SearchResult.TotalReplays replays in @stopWatch.ElapsedMilliseconds ms</p>
}

if (ProfileFound != null)
{
<p>Profile found for @ProfileFound.Username, click <a href="/player/@ProfileFound.PlayerGuid">here</a> to view</p>
}

<p>Page @pageDisplay of @SearchResult.PageCount</p>
<div class="replay-list">
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<PlayerData>();
}

SearchResult = loadedReplays;
stopWatch.Stop();
Expand Down
25 changes: 25 additions & 0 deletions Server/Api/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,31 @@ [FromQuery] string username
return Ok(completions);
}

/// <summary>
/// Tries to find a player with the given username. If found, returns the player's GUID.
/// </summary>
[HttpGet]
[Route("has-profile")]
public async Task<PlayerData> 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<LeaderboardData> GetLeaderboard(
Expand Down
4 changes: 3 additions & 1 deletion Server/Api/ReplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public async Task<ActionResult> SearchReplays(
PageCount = pageCount,
CurrentPage = page,
TotalReplays = found.Item2,
IsCache = found.Item3
IsCache = found.Item3,
SearchMode = searchMode,
Query = query
});
}

Expand Down
2 changes: 2 additions & 0 deletions Shared/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class SearchResult
public int CurrentPage { get; set; } = 1;
public List<Replay> Replays { get; set; } = new();
public int TotalReplays { get; set; } = 0;
public SearchMode SearchMode { get; set; }
public string Query { get; set; } = "";
}

0 comments on commit 63c6044

Please sign in to comment.