1 Commits

Author SHA1 Message Date
6727cbbe1e paginacja 2025-07-16 10:16:13 +02:00
2 changed files with 22 additions and 6 deletions

View File

@@ -38,12 +38,28 @@ public class QuotesController : ControllerBase
[ProducesResponseType(typeof(List<QuoteShortDTO>), 200)] [ProducesResponseType(typeof(List<QuoteShortDTO>), 200)]
[ProducesResponseType(typeof(ErrorDTO), 404)] [ProducesResponseType(typeof(ErrorDTO), 404)]
public async Task<IActionResult> GetQuotePage(int page_no) public async Task<IActionResult> GetQuotePage(int page_no)
{ {
// TODO... var totalQuotes = await _db.Quotes.CountAsync();
const int PageSize = 10;
if (page_no <= 0)
{
return NotFound(new ErrorDTO { Status = "error", error_msg = "Numer strony musi być większy niż 0." });
}
var quotes = await _db.Quotes.Include(q => q.QuoteCategories).ThenInclude(qc => qc.Category).Include(q => q.User).Include(q => q.Image).OrderBy(q => q.Id).Skip((page_no-1)*PageSize).Take(PageSize).ToListAsync();
if (quotes == null || totalQuotes == 0)
{
return NotFound(new ErrorDTO { Status = "error", error_msg = "Brak cytatów na tej stronie." });
}
var result = quotes.Select(q => q.ToQuoteShortDTO(_db)).ToList();
//return NotFound(new { status = "error", error_msg = "Not implemented" });
return Ok(result);
return NotFound(new { status = "error", error_msg = "Not implemented" });
// TODO: Consider turning the quote into a DTO
} }
// GET /api/v1/quotes/{id} // GET /api/v1/quotes/{id}

View File

@@ -3,5 +3,5 @@ namespace QuotifyBE.DTOs;
public record class ErrorDTO public record class ErrorDTO
{ {
public string Status { get; set; } public string Status { get; set; }
public string Error_msg { get; set; } public string error_msg { get; set; }
} }