diff --git a/Controllers/QuoteController.cs b/Controllers/QuoteController.cs index bd869db..89d93a9 100644 --- a/Controllers/QuoteController.cs +++ b/Controllers/QuoteController.cs @@ -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