diff --git a/Controllers/CategoryController.cs b/Controllers/CategoryController.cs index b0cefe5..a4735e3 100644 --- a/Controllers/CategoryController.cs +++ b/Controllers/CategoryController.cs @@ -27,7 +27,7 @@ public class CategoryController : ControllerBase guhf = GUHF; } - // GET /api/v1/categories + // GET /api/v1/categories/page/1 /// /// Get a category page /// @@ -40,7 +40,7 @@ public class CategoryController : ControllerBase /// Returned when requested page is invalid (page_no <= 0) [HttpGet("page/{page_no}")] [EnableCors] - [ProducesResponseType(typeof(CategoryShortDTO), 200)] + [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(ErrorDTO), 404)] public async Task GetCategoryPage(int page_no = 1) { @@ -78,6 +78,47 @@ public class CategoryController : ControllerBase } + // GET /api/v1/categories + /// + /// [AUTHED] Get every category + /// + /// + /// Can (and will) return an empty list if no categories are found in DB.
+ /// Unlike GET /api/v1/categories/page/..., requires authorization with a JWT. + /// Has CORS set. + ///
+ /// Returned on valid request + // /// Returned when there are no categories to list + [HttpGet] + [Authorize] + [EnableCors] + [ProducesResponseType(typeof(List), 200)] + public async Task GetQuotePage() + { + // The following seems to be a bad idea, so I leave it as is. ~eee4 + // + // int totalCategories = await _db.Categories.CountAsync(); + // + // if (totalCategories <= 0) + // { + // return NotFound(new ErrorDTO { Status = "error", Error_msg = "No categories to list" }); + // } + + // Get all the categories + List categories = await _db.Categories + .ToListAsync(); + + // Convert them to a list of DTO + List result = categories + .Select(c => c.ToCategoryShortDTO()) + .ToList(); + + // Return to user + return Ok(result); + + } + + // POST /api/v1/categories /// /// [AUTHED] Create a new category