Skip to content

Commit 63c6044

Browse files
committed
Add option to view profile from search result.
Fixes #4
1 parent 3af7fa7 commit 63c6044

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

Client/Components/Pages/Search.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
{
5353
<p>Found @SearchResult.TotalReplays replays in @stopWatch.ElapsedMilliseconds ms</p>
5454
}
55+
56+
if (ProfileFound != null)
57+
{
58+
<p>Profile found for @ProfileFound.Username, click <a href="/player/@ProfileFound.PlayerGuid">here</a> to view</p>
59+
}
5560

5661
<p>Page @pageDisplay of @SearchResult.PageCount</p>
5762
<div class="replay-list">
@@ -99,6 +104,7 @@
99104
public string? ErrorMessage { get; set; }
100105
public string? ErrorDetails { get; set; }
101106
public Stopwatch stopWatch { get; set; } = new Stopwatch();
107+
public PlayerData? ProfileFound { get; set; }
102108

103109
public SearchResult SearchResult { get; set; } = new SearchResult();
104110

@@ -136,6 +142,12 @@
136142
stopWatch.Stop();
137143
return;
138144
}
145+
146+
if (loadedReplays.SearchMode is SearchMode.PlayerOocName)
147+
{
148+
var playerGuid = await Http.GetAsync("/api/Data/has-profile?username=" + loadedReplays.Query);
149+
ProfileFound = await playerGuid.Content.ReadFromJsonAsync<PlayerData>();
150+
}
139151

140152
SearchResult = loadedReplays;
141153
stopWatch.Stop();

Server/Api/DataController.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,31 @@ [FromQuery] string username
192192
return Ok(completions);
193193
}
194194

195+
/// <summary>
196+
/// Tries to find a player with the given username. If found, returns the player's GUID.
197+
/// </summary>
198+
[HttpGet]
199+
[Route("has-profile")]
200+
public async Task<PlayerData> HasProfile(
201+
[FromQuery] string username
202+
)
203+
{
204+
var player = await _context.Players
205+
.FirstOrDefaultAsync(p => p.PlayerOocName.ToLower() == username.ToLower());
206+
if (player == null)
207+
return new PlayerData()
208+
{
209+
PlayerGuid = Guid.Empty,
210+
Username = "NOT FOUND"
211+
};
212+
213+
return new PlayerData()
214+
{
215+
PlayerGuid = player.PlayerGuid,
216+
Username = player.PlayerOocName
217+
};
218+
}
219+
195220
[HttpGet]
196221
[Route("leaderboard")]
197222
public async Task<LeaderboardData> GetLeaderboard(

Server/Api/ReplayController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public async Task<ActionResult> SearchReplays(
109109
PageCount = pageCount,
110110
CurrentPage = page,
111111
TotalReplays = found.Item2,
112-
IsCache = found.Item3
112+
IsCache = found.Item3,
113+
SearchMode = searchMode,
114+
Query = query
113115
});
114116
}
115117

Shared/SearchResult.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ public class SearchResult
1212
public int CurrentPage { get; set; } = 1;
1313
public List<Replay> Replays { get; set; } = new();
1414
public int TotalReplays { get; set; } = 0;
15+
public SearchMode SearchMode { get; set; }
16+
public string Query { get; set; } = "";
1517
}

0 commit comments

Comments
 (0)