2 Commits

Author SHA1 Message Date
ceb1829eb9 fix: load images for randomly drawn quotes 2025-07-23 09:58:28 +02:00
a1086b94f1 feat: bring back categories endpoint with no pagination
now it requires authorization
2025-07-23 09:44:56 +02:00
2 changed files with 45 additions and 5 deletions

View File

@@ -27,7 +27,7 @@ public class CategoryController : ControllerBase
guhf = GUHF;
}
// GET /api/v1/categories
// GET /api/v1/categories/page/1
/// <summary>
/// Get a category page
/// </summary>
@@ -40,7 +40,7 @@ public class CategoryController : ControllerBase
/// <response code="404">Returned when requested page is invalid (page_no &lt;= 0)</response>
[HttpGet("page/{page_no}")]
[EnableCors]
[ProducesResponseType(typeof(CategoryShortDTO), 200)]
[ProducesResponseType(typeof(List<CategoryShortDTO>), 200)]
[ProducesResponseType(typeof(ErrorDTO), 404)]
public async Task<IActionResult> GetCategoryPage(int page_no = 1)
{
@@ -78,6 +78,47 @@ public class CategoryController : ControllerBase
}
// GET /api/v1/categories
/// <summary>
/// [AUTHED] Get every category
/// </summary>
/// <remarks>
/// Can (and will) return an empty list if no categories are found in DB. <br/>
/// Unlike GET /api/v1/categories/page/..., requires authorization with a JWT.
/// Has CORS set.
/// </remarks>
/// <response code="200">Returned on valid request</response>
// /// <response code="404">Returned when there are no categories to list</response>
[HttpGet]
[Authorize]
[EnableCors]
[ProducesResponseType(typeof(List<CategoryShortDTO>), 200)]
public async Task<IActionResult> 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<Category> categories = await _db.Categories
.ToListAsync();
// Convert them to a list of DTO
List<CategoryShortDTO> result = categories
.Select(c => c.ToCategoryShortDTO())
.ToList();
// Return to user
return Ok(result);
}
// POST /api/v1/categories
/// <summary>
/// [AUTHED] Create a new category

View File

@@ -255,7 +255,8 @@ public class QuotesController : ControllerBase
{
IQueryable<Quote> query = _db.Quotes
.Include(q => q.QuoteCategories!)
.ThenInclude(qc => qc.Category);
.ThenInclude(qc => qc.Category)
.Include(q => q.Image);
if (category_id.HasValue)
{
@@ -278,8 +279,6 @@ public class QuotesController : ControllerBase
var skip = random.Next(0, totalQuotes);
var quote = await query
.Include(q => q.QuoteCategories!)
.ThenInclude(qc => qc.Category)
.Skip(skip)
.Take(1)
.FirstOrDefaultAsync();