mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 11:20:05 +01:00
Compare commits
2 Commits
ba162c34cc
...
ceb1829eb9
| Author | SHA1 | Date | |
|---|---|---|---|
| ceb1829eb9 | |||
| a1086b94f1 |
@@ -27,7 +27,7 @@ public class CategoryController : ControllerBase
|
|||||||
guhf = GUHF;
|
guhf = GUHF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/v1/categories
|
// GET /api/v1/categories/page/1
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a category page
|
/// Get a category page
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -40,7 +40,7 @@ public class CategoryController : ControllerBase
|
|||||||
/// <response code="404">Returned when requested page is invalid (page_no <= 0)</response>
|
/// <response code="404">Returned when requested page is invalid (page_no <= 0)</response>
|
||||||
[HttpGet("page/{page_no}")]
|
[HttpGet("page/{page_no}")]
|
||||||
[EnableCors]
|
[EnableCors]
|
||||||
[ProducesResponseType(typeof(CategoryShortDTO), 200)]
|
[ProducesResponseType(typeof(List<CategoryShortDTO>), 200)]
|
||||||
[ProducesResponseType(typeof(ErrorDTO), 404)]
|
[ProducesResponseType(typeof(ErrorDTO), 404)]
|
||||||
public async Task<IActionResult> GetCategoryPage(int page_no = 1)
|
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
|
// POST /api/v1/categories
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// [AUTHED] Create a new category
|
/// [AUTHED] Create a new category
|
||||||
|
|||||||
@@ -255,7 +255,8 @@ public class QuotesController : ControllerBase
|
|||||||
{
|
{
|
||||||
IQueryable<Quote> query = _db.Quotes
|
IQueryable<Quote> query = _db.Quotes
|
||||||
.Include(q => q.QuoteCategories!)
|
.Include(q => q.QuoteCategories!)
|
||||||
.ThenInclude(qc => qc.Category);
|
.ThenInclude(qc => qc.Category)
|
||||||
|
.Include(q => q.Image);
|
||||||
|
|
||||||
if (category_id.HasValue)
|
if (category_id.HasValue)
|
||||||
{
|
{
|
||||||
@@ -278,8 +279,6 @@ public class QuotesController : ControllerBase
|
|||||||
var skip = random.Next(0, totalQuotes);
|
var skip = random.Next(0, totalQuotes);
|
||||||
|
|
||||||
var quote = await query
|
var quote = await query
|
||||||
.Include(q => q.QuoteCategories!)
|
|
||||||
.ThenInclude(qc => qc.Category)
|
|
||||||
.Skip(skip)
|
.Skip(skip)
|
||||||
.Take(1)
|
.Take(1)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user