diff --git a/LeaderboardBackend.Test/Categories.cs b/LeaderboardBackend.Test/Categories.cs index 59120f99..14c0054f 100644 --- a/LeaderboardBackend.Test/Categories.cs +++ b/LeaderboardBackend.Test/Categories.cs @@ -4,7 +4,6 @@ using LeaderboardBackend.Models.Entities; using LeaderboardBackend.Models.Requests; using LeaderboardBackend.Models.ViewModels; -using LeaderboardBackend.Test.Lib; using LeaderboardBackend.Test.TestApi; using LeaderboardBackend.Test.TestApi.Extensions; using NUnit.Framework; @@ -52,7 +51,7 @@ await _apiClient.Get( public static async Task CreateCategory_GetCategory_OK() { LeaderboardViewModel createdLeaderboard = await _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = new CreateLeaderboardRequest() @@ -66,7 +65,7 @@ public static async Task CreateCategory_GetCategory_OK() ); CategoryViewModel createdCategory = await _apiClient.Post( - "/api/categories", + "/categories/create", new() { Body = new CreateCategoryRequest() @@ -83,7 +82,7 @@ public static async Task CreateCategory_GetCategory_OK() ); CategoryViewModel retrievedCategory = await _apiClient.Get( - $"/api/categories/{createdCategory?.Id}", new() { } + $"/api/category/{createdCategory?.Id}", new() { } ); Assert.AreEqual(createdCategory, retrievedCategory); diff --git a/LeaderboardBackend.Test/Leaderboards.cs b/LeaderboardBackend.Test/Leaderboards.cs index 215b2c4d..79e75936 100644 --- a/LeaderboardBackend.Test/Leaderboards.cs +++ b/LeaderboardBackend.Test/Leaderboards.cs @@ -46,7 +46,7 @@ public void GetLeaderboard_NotFound() RequestFailureException e = Assert.ThrowsAsync( async () => await _apiClient.Get( - $"/api/leaderboards/{long.MaxValue}", + $"/api/leaderboard/{long.MaxValue}", new() ) )!; @@ -59,12 +59,12 @@ public async Task CreateLeaderboard_GetLeaderboard_OK() { CreateLeaderboardRequest req = _createBoardReqFaker.Generate(); LeaderboardViewModel createdLeaderboard = await _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = req, Jwt = _jwt } ); LeaderboardViewModel retrievedLeaderboard = await _apiClient.Get( - $"/api/leaderboards/{createdLeaderboard?.Id}", + $"/api/leaderboard/{createdLeaderboard?.Id}", new() ); @@ -87,7 +87,7 @@ public async Task CreateLeaderboards_GetLeaderboards() .Select( req => _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = req, Jwt = _jwt } ) ); @@ -109,7 +109,7 @@ public async Task GetLeaderboards_BySlug_OK() { CreateLeaderboardRequest createReqBody = _createBoardReqFaker.Generate(); LeaderboardViewModel createdLeaderboard = await _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = createReqBody, Jwt = _jwt } ); @@ -117,13 +117,13 @@ public async Task GetLeaderboards_BySlug_OK() foreach (CreateLeaderboardRequest req in _createBoardReqFaker.Generate(2)) { await _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = req, Jwt = _jwt } ); } LeaderboardViewModel leaderboard = await _apiClient.Get( - $"api/leaderboards/{createReqBody.Slug}", + $"api/leaderboard?slug={createReqBody.Slug}", new() ); @@ -137,13 +137,13 @@ public async Task GetLeaderboards_BySlug_NotFound() foreach (CreateLeaderboardRequest req in _createBoardReqFaker.Generate(2)) { await _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = req, Jwt = _jwt } ); } CreateLeaderboardRequest reqForInexistentBoard = _createBoardReqFaker.Generate(); - Func> act = async () => await _apiClient.Get($"/api/leaderboards/{reqForInexistentBoard.Slug}", new()); + Func> act = async () => await _apiClient.Get($"/api/leaderboard?slug={reqForInexistentBoard.Slug}", new()); await act.Should().ThrowAsync().Where(e => e.Response.StatusCode == HttpStatusCode.NotFound); } diff --git a/LeaderboardBackend.Test/Runs.cs b/LeaderboardBackend.Test/Runs.cs index ff255520..344faade 100644 --- a/LeaderboardBackend.Test/Runs.cs +++ b/LeaderboardBackend.Test/Runs.cs @@ -4,7 +4,6 @@ using LeaderboardBackend.Models.Entities; using LeaderboardBackend.Models.Requests; using LeaderboardBackend.Models.ViewModels; -using LeaderboardBackend.Test.Lib; using LeaderboardBackend.Test.TestApi; using LeaderboardBackend.Test.TestApi.Extensions; using NodaTime; @@ -35,7 +34,7 @@ public async Task SetUp() _jwt = (await _apiClient.LoginAdminUser()).Token; LeaderboardViewModel createdLeaderboard = await _apiClient.Post( - "/api/leaderboards", + "/leaderboards/create", new() { Body = new CreateLeaderboardRequest() @@ -49,7 +48,7 @@ public async Task SetUp() ); CategoryViewModel createdCategory = await _apiClient.Post( - "/api/categories", + "/categories/create", new() { Body = new CreateCategoryRequest() @@ -85,7 +84,7 @@ public static async Task GetCategory_OK() RunViewModel createdRun = await CreateRun(); CategoryViewModel category = await _apiClient.Get( - $"api/runs/{createdRun.Id.ToUrlSafeBase64String()}/category", + $"api/run/{createdRun.Id.ToUrlSafeBase64String()}/category", new() { Jwt = _jwt } ); @@ -96,7 +95,7 @@ public static async Task GetCategory_OK() private static async Task CreateRun() { return await _apiClient.Post( - "/api/runs", + "/runs/create", new() { Body = new CreateRunRequest @@ -113,7 +112,7 @@ private static async Task CreateRun() private static async Task GetRun(Guid id) { - return await _apiClient.Get($"/api/runs/{id.ToUrlSafeBase64String()}", new() { Jwt = _jwt }); + return await _apiClient.Get($"/api/run/{id.ToUrlSafeBase64String()}", new() { Jwt = _jwt }); } } } diff --git a/LeaderboardBackend/Controllers/ApiController.cs b/LeaderboardBackend/Controllers/ApiController.cs index 391e19f8..984c2fdf 100644 --- a/LeaderboardBackend/Controllers/ApiController.cs +++ b/LeaderboardBackend/Controllers/ApiController.cs @@ -6,7 +6,6 @@ namespace LeaderboardBackend.Controllers; [ApiController] [Consumes("application/json")] [Produces("application/json")] -[Route("api/[controller]")] [SwaggerResponse(400, Type = typeof(ProblemDetails))] [SwaggerResponse(500)] public abstract class ApiController : ControllerBase { } diff --git a/LeaderboardBackend/Controllers/CategoriesController.cs b/LeaderboardBackend/Controllers/CategoriesController.cs index 238a5be3..4b58c1d4 100644 --- a/LeaderboardBackend/Controllers/CategoriesController.cs +++ b/LeaderboardBackend/Controllers/CategoriesController.cs @@ -19,7 +19,7 @@ public CategoriesController(ICategoryService categoryService) } [AllowAnonymous] - [HttpGet("{id}")] + [HttpGet("api/category/{id}")] [SwaggerOperation("Gets a Category by its ID.")] [SwaggerResponse(200)] [SwaggerResponse(404)] @@ -36,7 +36,7 @@ public async Task> GetCategory(long id) } [Authorize(Policy = UserTypes.ADMINISTRATOR)] - [HttpPost] + [HttpPost("categories/create")] [SwaggerOperation("Creates a new Category. This request is restricted to Moderators.")] [SwaggerResponse(201)] [SwaggerResponse(403)] diff --git a/LeaderboardBackend/Controllers/LeaderboardsController.cs b/LeaderboardBackend/Controllers/LeaderboardsController.cs index 20045bf6..7e91e053 100644 --- a/LeaderboardBackend/Controllers/LeaderboardsController.cs +++ b/LeaderboardBackend/Controllers/LeaderboardsController.cs @@ -19,7 +19,7 @@ public LeaderboardsController(ILeaderboardService leaderboardService) } [AllowAnonymous] - [HttpGet("{id:long}")] + [HttpGet("api/leaderboard/{id:long}")] [SwaggerOperation("Gets a leaderboard by its ID.")] [SwaggerResponse(200)] [SwaggerResponse(404)] @@ -36,11 +36,11 @@ public async Task> GetLeaderboard(long id) } [AllowAnonymous] - [HttpGet("{slug}")] + [HttpGet("api/leaderboard")] [SwaggerOperation("Gets a Leaderboard by its slug.")] [SwaggerResponse(200)] [SwaggerResponse(404)] - public async Task> GetLeaderboardBySlug(string slug) + public async Task> GetLeaderboardBySlug([FromQuery, SwaggerParameter(Required = true)] string slug) { Leaderboard? leaderboard = await _leaderboardService.GetLeaderboardBySlug(slug); @@ -53,7 +53,7 @@ public async Task> GetLeaderboardBySlug(strin } [AllowAnonymous] - [HttpGet] + [HttpGet("api/leaderboards")] [SwaggerOperation("Gets leaderboards by their IDs.")] [SwaggerResponse(200)] public async Task>> GetLeaderboards( @@ -65,7 +65,7 @@ [FromQuery] long[] ids } [Authorize(Policy = UserTypes.ADMINISTRATOR)] - [HttpPost] + [HttpPost("leaderboards/create")] [SwaggerOperation("Creates a new leaderboard. This request is restricted to Administrators.")] [SwaggerResponse(201)] [SwaggerResponse(401)] diff --git a/LeaderboardBackend/Controllers/RunsController.cs b/LeaderboardBackend/Controllers/RunsController.cs index a6a00c19..aefdcb9c 100644 --- a/LeaderboardBackend/Controllers/RunsController.cs +++ b/LeaderboardBackend/Controllers/RunsController.cs @@ -17,7 +17,7 @@ IUserService userService ) : ApiController { [AllowAnonymous] - [HttpGet("{id}")] + [HttpGet("api/run/{id}")] [SwaggerOperation("Gets a Run by its ID.")] [SwaggerResponse(200)] [SwaggerResponse(404)] @@ -34,7 +34,7 @@ public async Task> GetRun(Guid id) } [Authorize] - [HttpPost] + [HttpPost("runs/create")] [SwaggerOperation("Creates a new Run.")] [SwaggerResponse(201)] [SwaggerResponse(401)] @@ -63,7 +63,7 @@ public async Task CreateRun([FromBody] CreateRunRequest request) return Unauthorized(); } - [HttpGet("{id}/category")] + [HttpGet("/api/run/{id}/category")] [SwaggerResponse(200)] [SwaggerResponse(404)] public async Task> GetCategoryForRun(Guid id) diff --git a/LeaderboardBackend/Controllers/UsersController.cs b/LeaderboardBackend/Controllers/UsersController.cs index 52f0a9cb..f1f48fbe 100644 --- a/LeaderboardBackend/Controllers/UsersController.cs +++ b/LeaderboardBackend/Controllers/UsersController.cs @@ -19,7 +19,7 @@ public UsersController(IUserService userService) } [AllowAnonymous] - [HttpGet("{id:guid}")] + [HttpGet("api/user/{id:guid}")] [SwaggerOperation("Gets a User by their ID.")] [SwaggerResponse(200, "The `User` was found and returned successfully.")] [SwaggerResponse(404, "No `User` with the requested ID could be found.")] @@ -38,7 +38,7 @@ public async Task> GetUserById( } [Authorize] - [HttpGet("me")] + [HttpGet("user/me")] [SwaggerOperation( "Gets the currently logged-in User.", """ diff --git a/LeaderboardBackend/Services/Impl/LeaderboardService.cs b/LeaderboardBackend/Services/Impl/LeaderboardService.cs index e0335f84..506a715b 100644 --- a/LeaderboardBackend/Services/Impl/LeaderboardService.cs +++ b/LeaderboardBackend/Services/Impl/LeaderboardService.cs @@ -17,9 +17,9 @@ public LeaderboardService(ApplicationContext applicationContext) return await _applicationContext.Leaderboards.FindAsync(id); } - public Task GetLeaderboardBySlug(string slug) + public async Task GetLeaderboardBySlug(string slug) { - return _applicationContext.Leaderboards + return await _applicationContext.Leaderboards .AsNoTracking() .FirstOrDefaultAsync(x => x.Slug == slug); } diff --git a/LeaderboardBackend/openapi.json b/LeaderboardBackend/openapi.json index e6b6c2cd..f08a0d34 100644 --- a/LeaderboardBackend/openapi.json +++ b/LeaderboardBackend/openapi.json @@ -351,7 +351,7 @@ } } }, - "/api/Categories/{id}": { + "/api/category/{id}": { "get": { "tags": [ "Categories" @@ -398,7 +398,7 @@ } } }, - "/api/Categories": { + "/categories/create": { "post": { "tags": [ "Categories" @@ -453,7 +453,7 @@ } } }, - "/api/Leaderboards/{id}": { + "/api/leaderboard/{id}": { "get": { "tags": [ "Leaderboards" @@ -500,7 +500,7 @@ } } }, - "/api/Leaderboards/{slug}": { + "/api/leaderboard": { "get": { "tags": [ "Leaderboards" @@ -509,7 +509,7 @@ "parameters": [ { "name": "slug", - "in": "path", + "in": "query", "required": true, "schema": { "type": "string" @@ -546,7 +546,7 @@ } } }, - "/api/Leaderboards": { + "/api/leaderboards": { "get": { "tags": [ "Leaderboards" @@ -593,7 +593,9 @@ } } } - }, + } + }, + "/leaderboards/create": { "post": { "tags": [ "Leaderboards" @@ -651,7 +653,7 @@ } } }, - "/api/Runs/{id}": { + "/api/run/{id}": { "get": { "tags": [ "Runs" @@ -708,7 +710,7 @@ } } }, - "/api/Runs": { + "/runs/create": { "post": { "tags": [ "Runs" @@ -759,7 +761,7 @@ } } }, - "/api/Runs/{id}/category": { + "/api/run/{id}/category": { "get": { "tags": [ "Runs" @@ -805,7 +807,7 @@ } } }, - "/api/Users/{id}": { + "/api/user/{id}": { "get": { "tags": [ "Users" @@ -853,7 +855,7 @@ } } }, - "/api/Users/me": { + "/user/me": { "get": { "tags": [ "Users"