diff --git a/LeaderboardBackend.Test/Categories.cs b/LeaderboardBackend.Test/Categories.cs index 1762cecb..e7450e88 100644 --- a/LeaderboardBackend.Test/Categories.cs +++ b/LeaderboardBackend.Test/Categories.cs @@ -64,10 +64,52 @@ public async Task OneTimeSetUp() public void OneTimeTearDown() => _factory.Dispose(); [Test] - public async Task GetCategory_NotFound() => + public async Task GetCategory_OK() + { + IServiceScope scope = _factory.Services.CreateScope(); + ApplicationContext context = scope.ServiceProvider.GetRequiredService(); + + Category created = new() + { + Name = "get ok", + Slug = "getcategory-ok", + LeaderboardId = _createdLeaderboard.Id, + SortDirection = SortDirection.Ascending, + Type = RunType.Score, + }; + + context.Add(created); + await context.SaveChangesAsync(); + created.Id.Should().NotBe(default); + + await _apiClient.Awaiting( + a => a.Get( + $"api/category/{created.Id}", + new() { } + ) + ).Should() + .NotThrowAsync() + .WithResult(new() + { + Id = created.Id, + Name = "get ok", + Slug = "getcategory-ok", + Info = "", + Type = RunType.Score, + SortDirection = SortDirection.Ascending, + LeaderboardId = _createdLeaderboard.Id, + CreatedAt = _clock.GetCurrentInstant(), + UpdatedAt = null, + DeletedAt = null, + }); + } + + [TestCase("NotANumber")] + [TestCase("69")] + public async Task GetCategory_NotFound(object id) => await _apiClient.Awaiting( a => a.Get( - $"/api/category/69", + $"/api/category/{id}", new() { Jwt = _jwt } ) ).Should() diff --git a/LeaderboardBackend/Controllers/CategoriesController.cs b/LeaderboardBackend/Controllers/CategoriesController.cs index 13d1b968..8c621745 100644 --- a/LeaderboardBackend/Controllers/CategoriesController.cs +++ b/LeaderboardBackend/Controllers/CategoriesController.cs @@ -14,7 +14,7 @@ namespace LeaderboardBackend.Controllers; public class CategoriesController(ICategoryService categoryService) : ApiController { [AllowAnonymous] - [HttpGet("api/category/{id}")] + [HttpGet("api/category/{id:long}")] [SwaggerOperation("Gets a Category by its ID.", OperationId = "getCategory")] [SwaggerResponse(200)] [SwaggerResponse(404)] diff --git a/LeaderboardBackend/Models/ViewModels/CategoryViewModel.cs b/LeaderboardBackend/Models/ViewModels/CategoryViewModel.cs index 0a643075..25e753f1 100644 --- a/LeaderboardBackend/Models/ViewModels/CategoryViewModel.cs +++ b/LeaderboardBackend/Models/ViewModels/CategoryViewModel.cs @@ -31,11 +31,15 @@ public record CategoryViewModel /// Video proof is required. public required string? Info { get; set; } + /// public required RunType Type { get; set; } /// public required SortDirection SortDirection { get; set; } + /// + public required long LeaderboardId { get; set; } + /// public required Instant CreatedAt { get; set; } @@ -53,6 +57,7 @@ public record CategoryViewModel Info = category.Info, SortDirection = category.SortDirection, Type = category.Type, + LeaderboardId = category.LeaderboardId, CreatedAt = category.CreatedAt, UpdatedAt = category.UpdatedAt, DeletedAt = category.DeletedAt diff --git a/LeaderboardBackend/openapi.json b/LeaderboardBackend/openapi.json index 5d504e30..bcbae924 100644 --- a/LeaderboardBackend/openapi.json +++ b/LeaderboardBackend/openapi.json @@ -1380,6 +1380,7 @@ "deletedAt", "id", "info", + "leaderboardId", "name", "slug", "sortDirection", @@ -1415,6 +1416,10 @@ "sortDirection": { "$ref": "#/components/schemas/SortDirection" }, + "leaderboardId": { + "type": "integer", + "format": "int64" + }, "createdAt": { "type": "string", "format": "date-time",