usuwanie kategorii (do przetestowania dla cytatow z kategoriami)

This commit is contained in:
2025-07-21 12:40:13 +02:00
parent a8a82df6ed
commit d502e9d120

View File

@@ -110,6 +110,41 @@ public class CategoryController : ControllerBase
}
[HttpDelete("{id}")]
[Authorize]
[EnableCors]
[ProducesResponseType(200)]
[ProducesResponseType(typeof(ErrorDTO), 404)]
public async Task<IActionResult> DeleteCategory(int id)
{
// (Attempt to) find the quote
Category? cat = await _db.Categories
.FirstOrDefaultAsync(c => c.Id == id);
// Failed?
if (cat == null)
return NotFound(new { status = "error", error_msg = "Quote not found" });
List<QuoteCategory> quoteLinks = await _db.QuoteCategories.Where(qc => qc.CategoryId == id).ToListAsync();
foreach (var link in quoteLinks) {
_db.QuoteCategories.Remove(link);
}
_db.Categories.Remove(cat);
await _db.SaveChangesAsync();
// ====================================================================== //
// Important! //
// Is this the best we can do? Won't marking the quote as "hidden" //
// be better than explicitly deleting it? ~eee4 //
// ====================================================================== //
// Return ok
return Ok(new { Status = "ok" });
}
// TODO: Update category
// PATCH /api/v1/categories/1
@@ -117,3 +152,4 @@ public class CategoryController : ControllerBase
// DELETE /api/v1/categories/1
}