Use query variables for leaderboard api request
This commit is contained in:
parent
cffeb188c8
commit
4612c27469
@ -14,24 +14,33 @@ public class SongLeaderboardController(ISongLeaderboardService songLeaderboardSe
|
||||
{
|
||||
private readonly AuthSettings authSettings = settings.Value;
|
||||
|
||||
[HttpGet("{baid}/{songId}/{difficulty}")]
|
||||
[HttpGet("{songId}")]
|
||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||
|
||||
public async Task<ActionResult<SongLeaderboardResponse>> GetSongLeaderboard(uint baid, uint songId, uint difficulty)
|
||||
public async Task<ActionResult<SongLeaderboardResponse>> GetSongLeaderboard(uint songId, [FromQuery] uint baid, [FromQuery] uint difficulty)
|
||||
{
|
||||
if (authSettings.AuthenticationRequired)
|
||||
// if baid id is provided, check authentication
|
||||
if (!baid.Equals(0))
|
||||
{
|
||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||
if (tokenInfo is null)
|
||||
if (authSettings.AuthenticationRequired)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||
if (tokenInfo is null)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (tokenInfo.Value.baid != baid && !tokenInfo.Value.isAdmin)
|
||||
{
|
||||
return Forbid();
|
||||
if (tokenInfo.Value.baid != baid && !tokenInfo.Value.isAdmin)
|
||||
{
|
||||
return Forbid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (difficulty < 1 || difficulty > 5)
|
||||
{
|
||||
return BadRequest(new { Message = "Invalid difficulty. Please provide a number between 1-5." });
|
||||
}
|
||||
|
||||
var leaderboard = await songLeaderboardService.GetSongLeaderboard(songId, (Difficulty)difficulty, (int)baid);
|
||||
|
||||
|
@ -32,11 +32,7 @@
|
||||
</MudGrid>
|
||||
</MudCardHeader>
|
||||
<MudCardContent Class="pa-0">
|
||||
@if (response == null || isLoading == true)
|
||||
{
|
||||
<MudCircularProgress />
|
||||
}
|
||||
else if (response.Leaderboard.Count == 0)
|
||||
@if (response == null || response.Leaderboard.Count == 0)
|
||||
{
|
||||
<MudGrid>
|
||||
<MudItem xs="12">
|
||||
@ -48,7 +44,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@response.Leaderboard" Class="leaderboard-table" Elevation="0" Outlined="false" Dense="true" Striped="true">
|
||||
<MudTable Loading="isLoading" Items="@response.Leaderboard" Class="leaderboard-table" Elevation="0" Outlined="false" Dense="true" Striped="true">
|
||||
<HeaderContent>
|
||||
<MudTh>@Localizer["Rank"]</MudTh>
|
||||
<MudTh>@Localizer["Player"]</MudTh>
|
||||
|
@ -37,7 +37,7 @@ public partial class SongLeaderboardCard
|
||||
Difficulty = Difficulty.Easy;
|
||||
}
|
||||
|
||||
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)Baid}/{(uint)SongId}/{(uint)Difficulty}");
|
||||
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}");
|
||||
response.ThrowIfNull();
|
||||
|
||||
isLoading = false;
|
||||
@ -51,7 +51,7 @@ public partial class SongLeaderboardCard
|
||||
|
||||
await LocalStorage.SetItemAsync("songPageDifficulty", SelectedDifficulty);
|
||||
|
||||
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)Baid}/{(uint)SongId}/{(uint)Difficulty}");
|
||||
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}");
|
||||
response.ThrowIfNull();
|
||||
isLoading = false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user