mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:20:06 +01:00
fix: pass DTO from API, and pass objects instead of raw ints
fixes cyclic import when passing categories
This commit is contained in:
@@ -158,13 +158,13 @@ public class QuotesController : ControllerBase
|
||||
// Attach categories
|
||||
foreach (var categoryId in request.CategoryIds ?? [])
|
||||
{
|
||||
var categoryExists = await _db.Categories.AnyAsync(c => c.Id == categoryId);
|
||||
if (!categoryExists)
|
||||
Category? category = await _db.Categories.FirstOrDefaultAsync(c => c.Id == categoryId);
|
||||
if (category == null)
|
||||
return BadRequest(new ErrorDTO { Status = "error", Error_msg = $"Category ID {categoryId} not found" });
|
||||
|
||||
quote.QuoteCategories.Add(new QuoteCategory
|
||||
{
|
||||
CategoryId = categoryId,
|
||||
Category = category,
|
||||
Quote = quote
|
||||
});
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class QuotesController : ControllerBase
|
||||
_db.Quotes.Add(quote);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetQuoteById), new { id = quote.Id }, quote);
|
||||
return CreatedAtAction(nameof(GetQuoteById), new { id = quote.Id }, quote.ToQuoteShortDTO());
|
||||
}
|
||||
|
||||
// GET /api/v1/quotes/random
|
||||
|
||||
Reference in New Issue
Block a user