mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:00:07 +01:00
usuwanie kategorii (do przetestowania dla cytatow z kategoriami)
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user