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:
@@ -108,6 +108,41 @@ public class CategoryController : ControllerBase
|
|||||||
// And send back to the user as DTO
|
// And send back to the user as DTO
|
||||||
return Ok(cat.ToCategoryShortDTO());
|
return Ok(cat.ToCategoryShortDTO());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[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
|
// TODO: Update category
|
||||||
@@ -117,3 +152,4 @@ public class CategoryController : ControllerBase
|
|||||||
// DELETE /api/v1/categories/1
|
// DELETE /api/v1/categories/1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user