feat: comment update/delete endpoints

This commit is contained in:
Zhi
2026-02-22 04:22:54 +00:00
parent 955cf01110
commit 9d831e932c

View File

@@ -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