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
|
// Attach categories
|
||||||
foreach (var categoryId in request.CategoryIds ?? [])
|
foreach (var categoryId in request.CategoryIds ?? [])
|
||||||
{
|
{
|
||||||
var categoryExists = await _db.Categories.AnyAsync(c => c.Id == categoryId);
|
Category? category = await _db.Categories.FirstOrDefaultAsync(c => c.Id == categoryId);
|
||||||
if (!categoryExists)
|
if (category == null)
|
||||||
return BadRequest(new ErrorDTO { Status = "error", Error_msg = $"Category ID {categoryId} not found" });
|
return BadRequest(new ErrorDTO { Status = "error", Error_msg = $"Category ID {categoryId} not found" });
|
||||||
|
|
||||||
quote.QuoteCategories.Add(new QuoteCategory
|
quote.QuoteCategories.Add(new QuoteCategory
|
||||||
{
|
{
|
||||||
CategoryId = categoryId,
|
Category = category,
|
||||||
Quote = quote
|
Quote = quote
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ public class QuotesController : ControllerBase
|
|||||||
_db.Quotes.Add(quote);
|
_db.Quotes.Add(quote);
|
||||||
await _db.SaveChangesAsync();
|
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
|
// GET /api/v1/quotes/random
|
||||||
|
|||||||
Reference in New Issue
Block a user