Spaces:
Sleeping
Sleeping
Commit ·
16528b4
1
Parent(s): 7986b9b
Add DELETE comment API endpoint
Browse files- app/main.py +16 -0
app/main.py
CHANGED
|
@@ -331,6 +331,22 @@ def rate_comment(comment_id: int, rating_in: schemas.CommentRatingCreate, db: Se
|
|
| 331 |
return comment
|
| 332 |
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
# --- 🚀 Upgraded Scraping Endpoint ---
|
| 335 |
@app.post("/api/v1/articles/scrape", response_model=schemas.ArticleResponse)
|
| 336 |
def scrape_and_add_article(req: schemas.ScrapeRequest, db: Session = Depends(get_db)):
|
|
|
|
| 331 |
return comment
|
| 332 |
|
| 333 |
|
| 334 |
+
@app.delete("/api/v1/comments/{comment_id}")
|
| 335 |
+
def delete_comment(comment_id: int, db: Session = Depends(get_db), current_user: models.User = Depends(get_current_user)):
|
| 336 |
+
comment = db.query(models.Comment).filter(models.Comment.id == comment_id).first()
|
| 337 |
+
if not comment:
|
| 338 |
+
raise HTTPException(status_code=404, detail="التعليق غير موجود")
|
| 339 |
+
|
| 340 |
+
if comment.user_id != current_user.id:
|
| 341 |
+
raise HTTPException(status_code=403, detail="غير مصرح لك بحذف هذا التعليق")
|
| 342 |
+
|
| 343 |
+
# Delete associated ratings
|
| 344 |
+
db.query(models.CommentRating).filter(models.CommentRating.comment_id == comment_id).delete()
|
| 345 |
+
db.delete(comment)
|
| 346 |
+
db.commit()
|
| 347 |
+
return {"message": "تم حذف التعليق بنجاح", "id": comment_id}
|
| 348 |
+
|
| 349 |
+
|
| 350 |
# --- 🚀 Upgraded Scraping Endpoint ---
|
| 351 |
@app.post("/api/v1/articles/scrape", response_model=schemas.ArticleResponse)
|
| 352 |
def scrape_and_add_article(req: schemas.ScrapeRequest, db: Session = Depends(get_db)):
|