From 9d831e932c6b7354ce1fd32b90876a2d4ce30ed8 Mon Sep 17 00:00:00 2001 From: Zhi Date: Sun, 22 Feb 2026 04:22:54 +0000 Subject: [PATCH] feat: comment update/delete endpoints --- app/main.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/main.py b/app/main.py index a5de7b7..7ab445c 100644 --- a/app/main.py +++ b/app/main.py @@ -490,3 +490,28 @@ def dashboard_stats(project_id: int = None, db: Session = Depends(get_db)): "by_type": by_type, "by_priority": by_priority, } + + + +# ============ Comments (update/delete) ============ + +@app.patch("/comments/{comment_id}", response_model=schemas.CommentResponse) +def update_comment(comment_id: int, comment_update: schemas.CommentUpdate, db: Session = Depends(get_db)): + comment = db.query(models.Comment).filter(models.Comment.id == comment_id).first() + if not comment: + raise HTTPException(status_code=404, detail="Comment not found") + for field, value in comment_update.model_dump(exclude_unset=True).items(): + setattr(comment, field, value) + db.commit() + db.refresh(comment) + return comment + + +@app.delete("/comments/{comment_id}", status_code=status.HTTP_204_NO_CONTENT) +def delete_comment(comment_id: int, db: Session = Depends(get_db)): + comment = db.query(models.Comment).filter(models.Comment.id == comment_id).first() + if not comment: + raise HTTPException(status_code=404, detail="Comment not found") + db.delete(comment) + db.commit() + return None