Skip to content

Commit

Permalink
Get leaderboard endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
zysim committed Aug 18, 2024
1 parent b08efce commit f681017
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
6 changes: 2 additions & 4 deletions LeaderboardBackend/Controllers/LeaderboardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ public class LeaderboardsController : ApiController
{
private readonly ILeaderboardService _leaderboardService;

public LeaderboardsController(ILeaderboardService leaderboardService)
{
public LeaderboardsController(ILeaderboardService leaderboardService) =>
_leaderboardService = leaderboardService;
}

[AllowAnonymous]
[HttpGet("{id:long}")]
[HttpGet("/api/leaderboard/{id:long}")]
[SwaggerOperation("Gets a leaderboard by its ID.")]
[SwaggerResponse(200)]
[SwaggerResponse(404)]
Expand Down
13 changes: 5 additions & 8 deletions LeaderboardBackend/Services/Impl/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ public LeaderboardService(ApplicationContext applicationContext)
_applicationContext = applicationContext;
}

public async Task<Leaderboard?> GetLeaderboard(long id)
{
return await _applicationContext.Leaderboards.FindAsync(id);
}
public async Task<Leaderboard?> GetLeaderboard(long id) =>
await _applicationContext.Leaderboards
.FirstOrDefaultAsync(board => board.Id == id);

public Task<Leaderboard?> GetLeaderboardBySlug(string slug)
{
return _applicationContext.Leaderboards
public Task<Leaderboard?> GetLeaderboardBySlug(string slug) =>
_applicationContext.Leaderboards
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Slug == slug);
}

// FIXME: Paginate this
public async Task<List<Leaderboard>> GetLeaderboards(long[]? ids = null)
Expand Down
2 changes: 1 addition & 1 deletion LeaderboardBackend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
}
}
},
"/api/Leaderboards/{id}": {
"/api/leaderboard/{id}": {
"get": {
"tags": [
"Leaderboards"
Expand Down

0 comments on commit f681017

Please sign in to comment.