mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:20:06 +01:00
fix: return id for random quote as well
This commit is contained in:
@@ -38,25 +38,25 @@ 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)
|
||||||
{
|
{
|
||||||
var totalQuotes = await _db.Quotes.CountAsync();
|
var totalQuotes = await _db.Quotes.CountAsync();
|
||||||
const int PageSize = 10;
|
const int PageSize = 10;
|
||||||
|
|
||||||
if (page_no <= 0)
|
if (page_no <= 0)
|
||||||
{
|
{
|
||||||
return NotFound(new ErrorDTO { Status = "error", error_msg = "Numer strony musi być większy niż 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();
|
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)
|
if (quotes == null || totalQuotes == 0)
|
||||||
{
|
{
|
||||||
return NotFound(new ErrorDTO { Status = "error", error_msg = "Brak cytatów na tej stronie." });
|
return NotFound(new ErrorDTO { Status = "error", error_msg = "Brak cytatów na tej stronie." });
|
||||||
}
|
}
|
||||||
var result = quotes.Select(q => q.ToQuoteShortDTO(_db)).ToList();
|
var result = quotes.Select(q => q.ToQuoteShortDTO(_db)).ToList();
|
||||||
|
|
||||||
//return NotFound(new { status = "error", error_msg = "Not implemented" });
|
//return NotFound(new { status = "error", error_msg = "Not implemented" });
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
|
|
||||||
@@ -194,6 +194,7 @@ public class QuotesController : ControllerBase
|
|||||||
|
|
||||||
var dto = new QuoteShortDTO
|
var dto = new QuoteShortDTO
|
||||||
{
|
{
|
||||||
|
Id = quote.Id,
|
||||||
Text = quote.Text,
|
Text = quote.Text,
|
||||||
Author = quote.Author,
|
Author = quote.Author,
|
||||||
ImageUrl = image?.Url,
|
ImageUrl = image?.Url,
|
||||||
|
|||||||
Reference in New Issue
Block a user