diff --git a/LeaderboardBackend.Test/Leaderboards.cs b/LeaderboardBackend.Test/Leaderboards.cs index 44845d9a..2e7c5862 100644 --- a/LeaderboardBackend.Test/Leaderboards.cs +++ b/LeaderboardBackend.Test/Leaderboards.cs @@ -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() } ]; @@ -350,6 +351,12 @@ public async Task GetLeaderboards() await context.SaveChangesAsync(); LeaderboardViewModel[] returned = await _apiClient.Get("/api/leaderboards", new()); returned.Should().BeEquivalentTo(boards.Take(2), config => config.Excluding(lb => lb.Categories)); + + LeaderboardViewModel[] returned2 = await _apiClient.Get("/api/leaderboards?includeDeleted=false", new()); + returned2.Should().BeEquivalentTo(boards.Take(2), config => config.Excluding(lb => lb.Categories)); + + LeaderboardViewModel[] returned3 = await _apiClient.Get("/api/leaderboards?includeDeleted=true", new()); + returned3.Should().BeEquivalentTo(boards, config => config.Excluding(lb => lb.Categories)); } [Test] diff --git a/LeaderboardBackend/Controllers/LeaderboardsController.cs b/LeaderboardBackend/Controllers/LeaderboardsController.cs index f792f509..428b97fe 100644 --- a/LeaderboardBackend/Controllers/LeaderboardsController.cs +++ b/LeaderboardBackend/Controllers/LeaderboardsController.cs @@ -51,11 +51,11 @@ public async Task> GetLeaderboardBySlug([From [HttpGet("api/leaderboards")] [SwaggerOperation("Gets all leaderboards.", OperationId = "listLeaderboards")] [SwaggerResponse(200)] - public async Task>> GetLeaderboards() + public async Task>> GetLeaderboards([FromQuery] bool includeDeleted = false) { // TODO: Paginate. - List result = await leaderboardService.ListLeaderboards(); + List result = await leaderboardService.ListLeaderboards(includeDeleted); return Ok(result.Select(LeaderboardViewModel.MapFrom)); } diff --git a/LeaderboardBackend/Services/ILeaderboardService.cs b/LeaderboardBackend/Services/ILeaderboardService.cs index 2c3371d3..789a48fb 100644 --- a/LeaderboardBackend/Services/ILeaderboardService.cs +++ b/LeaderboardBackend/Services/ILeaderboardService.cs @@ -9,7 +9,7 @@ public interface ILeaderboardService { Task GetLeaderboard(long id); Task GetLeaderboardBySlug(string slug); - Task> ListLeaderboards(); + Task> ListLeaderboards(bool includeDeleted); Task CreateLeaderboard(CreateLeaderboardRequest request); Task RestoreLeaderboard(long id); Task DeleteLeaderboard(long id); diff --git a/LeaderboardBackend/Services/Impl/LeaderboardService.cs b/LeaderboardBackend/Services/Impl/LeaderboardService.cs index 35bdc1c8..d34489ee 100644 --- a/LeaderboardBackend/Services/Impl/LeaderboardService.cs +++ b/LeaderboardBackend/Services/Impl/LeaderboardService.cs @@ -18,9 +18,11 @@ await applicationContext.Leaderboards .FirstOrDefaultAsync(b => b.Slug == slug && b.DeletedAt == null); // FIXME: Paginate these - public async Task> ListLeaderboards() => - await applicationContext.Leaderboards - .Where(lb => lb.DeletedAt == null).ToListAsync(); + public async Task> ListLeaderboards(bool includeDeleted) + { + IQueryable lbs = applicationContext.Leaderboards; + return await (includeDeleted ? lbs : lbs.Where(lb => lb.DeletedAt == null)).ToListAsync(); + } public async Task CreateLeaderboard(CreateLeaderboardRequest request) { diff --git a/LeaderboardBackend/openapi.json b/LeaderboardBackend/openapi.json index c6434a82..485eac46 100644 --- a/LeaderboardBackend/openapi.json +++ b/LeaderboardBackend/openapi.json @@ -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",