Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

includeDeleted Param #255

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions LeaderboardBackend.Test/Leaderboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public async Task GetLeaderboards()
Name = "Link: The Faces of Evil",
Slug = "link-faces-of-evil",
Info = "Nobody should play this one.",
UpdatedAt = _clock.GetCurrentInstant(),
DeletedAt = _clock.GetCurrentInstant()
}
];
Expand All @@ -350,6 +351,12 @@ public async Task GetLeaderboards()
await context.SaveChangesAsync();
LeaderboardViewModel[] returned = await _apiClient.Get<LeaderboardViewModel[]>("/api/leaderboards", new());
returned.Should().BeEquivalentTo(boards.Take(2), config => config.Excluding(lb => lb.Categories));

LeaderboardViewModel[] returned2 = await _apiClient.Get<LeaderboardViewModel[]>("/api/leaderboards?includeDeleted=false", new());
returned2.Should().BeEquivalentTo(boards.Take(2), config => config.Excluding(lb => lb.Categories));

LeaderboardViewModel[] returned3 = await _apiClient.Get<LeaderboardViewModel[]>("/api/leaderboards?includeDeleted=true", new());
returned3.Should().BeEquivalentTo(boards, config => config.Excluding(lb => lb.Categories));
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions LeaderboardBackend/Controllers/LeaderboardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public async Task<ActionResult<LeaderboardViewModel>> GetLeaderboardBySlug([From
[HttpGet("api/leaderboards")]
[SwaggerOperation("Gets all leaderboards.", OperationId = "listLeaderboards")]
[SwaggerResponse(200)]
public async Task<ActionResult<List<LeaderboardViewModel>>> GetLeaderboards()
public async Task<ActionResult<List<LeaderboardViewModel>>> GetLeaderboards([FromQuery] bool includeDeleted = false)
{
// TODO: Paginate.

List<Leaderboard> result = await leaderboardService.ListLeaderboards();
List<Leaderboard> result = await leaderboardService.ListLeaderboards(includeDeleted);
return Ok(result.Select(LeaderboardViewModel.MapFrom));
}

Expand Down
2 changes: 1 addition & 1 deletion LeaderboardBackend/Services/ILeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ILeaderboardService
{
Task<Leaderboard?> GetLeaderboard(long id);
Task<Leaderboard?> GetLeaderboardBySlug(string slug);
Task<List<Leaderboard>> ListLeaderboards();
Task<List<Leaderboard>> ListLeaderboards(bool includeDeleted);
Task<CreateLeaderboardResult> CreateLeaderboard(CreateLeaderboardRequest request);
Task<RestoreLeaderboardResult> RestoreLeaderboard(long id);
Task<DeleteResult> DeleteLeaderboard(long id);
Expand Down
8 changes: 5 additions & 3 deletions LeaderboardBackend/Services/Impl/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ await applicationContext.Leaderboards
.FirstOrDefaultAsync(b => b.Slug == slug && b.DeletedAt == null);

// FIXME: Paginate these
public async Task<List<Leaderboard>> ListLeaderboards() =>
await applicationContext.Leaderboards
.Where(lb => lb.DeletedAt == null).ToListAsync();
public async Task<List<Leaderboard>> ListLeaderboards(bool includeDeleted)
{
IQueryable<Leaderboard> lbs = applicationContext.Leaderboards;
return await (includeDeleted ? lbs : lbs.Where(lb => lb.DeletedAt == null)).ToListAsync();
}

public async Task<CreateLeaderboardResult> CreateLeaderboard(CreateLeaderboardRequest request)
{
Expand Down
10 changes: 10 additions & 0 deletions LeaderboardBackend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,16 @@
],
"summary": "Gets all leaderboards.",
"operationId": "listLeaderboards",
"parameters": [
{
"name": "includeDeleted",
"in": "query",
"schema": {
"type": "boolean",
"default": false
}
}
],
"responses": {
"400": {
"description": "Bad Request",
Expand Down