From ff615ce3521d6fa0b6879685dd446d7893592dcf Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:09:20 -0400 Subject: [PATCH] Implement LB deletion endpoint. --- .../Controllers/LeaderboardsController.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/LeaderboardBackend/Controllers/LeaderboardsController.cs b/LeaderboardBackend/Controllers/LeaderboardsController.cs index cabf8bbb..2acc4049 100644 --- a/LeaderboardBackend/Controllers/LeaderboardsController.cs +++ b/LeaderboardBackend/Controllers/LeaderboardsController.cs @@ -3,6 +3,7 @@ using LeaderboardBackend.Models.Requests; using LeaderboardBackend.Models.Validation; using LeaderboardBackend.Models.ViewModels; +using LeaderboardBackend.Result; using LeaderboardBackend.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -86,4 +87,29 @@ public async Task> CreateLeaderboard( } ); } + + [Authorize(Policy = UserTypes.ADMINISTRATOR)] + [HttpDelete("leaderboard/{id:long}")] + [SwaggerOperation("Deletes a leaderboard. This request is restricted to Administrators.", OperationId = "deleteLeaderboard")] + [SwaggerResponse(204)] + [SwaggerResponse(401)] + [SwaggerResponse(403)] + [SwaggerResponse( + 404, + """ + The leaderboard does not exist (Not Found) or was already deleted (Already Deleted). + Use the title field of the response to differentiate between the two cases if necessary. + """, + typeof(ProblemDetails) + )] + public async Task DeleteLeaderboard([FromRoute, SwaggerParameter(Required = true)] long id) + { + DeleteResult res = await leaderboardService.DeleteLeaderboard(id); + + return res.Match( + success => NoContent(), + notFound => NotFound(), + alreadyDeleted => NotFound(ProblemDetailsFactory.CreateProblemDetails(HttpContext, 404, "Already Deleted")) + ); + } }