From 0ad319f2450f8930998063e0085634ad30807c42 Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:52:35 -0400 Subject: [PATCH 1/3] Test the includeDeleted parameter. --- LeaderboardBackend.Test/Leaderboards.cs | 7 +++++++ 1 file changed, 7 insertions(+) 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] From 42e3357e15ddbe4fc8458e89e14379975346028d Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:55:53 -0400 Subject: [PATCH 2/3] Add includeDeleted param to ListLeaderboards. --- LeaderboardBackend/Services/ILeaderboardService.cs | 2 +- LeaderboardBackend/Services/Impl/LeaderboardService.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) 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) { From 98e720ddb79245f80835dc614ad3980bb99d1ff3 Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:56:27 -0400 Subject: [PATCH 3/3] Add query includeDeleted query param. --- .../Controllers/LeaderboardsController.cs | 4 ++-- LeaderboardBackend/openapi.json | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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/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",