Skip to content

Commit

Permalink
Implement LB deletion endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTedder committed Oct 19, 2024
1 parent 049aa14 commit ff615ce
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions LeaderboardBackend/Controllers/LeaderboardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,4 +87,29 @@ public async Task<ActionResult<LeaderboardViewModel>> 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<ActionResult> DeleteLeaderboard([FromRoute, SwaggerParameter(Required = true)] long id)
{
DeleteResult res = await leaderboardService.DeleteLeaderboard(id);

return res.Match<ActionResult>(
success => NoContent(),
notFound => NotFound(),
alreadyDeleted => NotFound(ProblemDetailsFactory.CreateProblemDetails(HttpContext, 404, "Already Deleted"))
);
}
}

0 comments on commit ff615ce

Please sign in to comment.