feat: basic stats endpoint

This commit is contained in:
2025-07-22 11:39:40 +02:00
parent 468d502827
commit 341755d77e
2 changed files with 67 additions and 1 deletions

View File

@@ -216,9 +216,10 @@ public class QuotesController : ControllerBase
// GET /api/v1/quotes/random
/// <summary>
/// Get a random quote summary
/// Draw a random quote
/// </summary>
/// <returns>A quote: id, quote content and author, imageUrl and categories if successful, otherwise: error message</returns>
/// <param name="category_id">(Optional) category id to draw from</param>
/// <response code="200">Returned on valid request</response>
/// <response code="204">Returned when no quotes exist matching provided criteria</response>
/// <response code="404">Returned when no quotes exist (in the DB)</response>
@@ -263,6 +264,12 @@ public class QuotesController : ControllerBase
if (quote == null)
return NotFound(new ErrorDTO { Status = "error", Error_msg = "Unknown error - couldn't get quote" });
// After getting and checking the quote, update the number of draws
Statistic s = await _db.Statistics
.FirstAsync(s => s.Label == "number_of_draws");
s.IValue += 1;
await _db.SaveChangesAsync();
return Ok(quote.ToQuoteShortDTO());
}