feat: comment update/delete endpoints
This commit is contained in:
25
app/main.py
25
app/main.py
@@ -490,3 +490,28 @@ def dashboard_stats(project_id: int = None, db: Session = Depends(get_db)):
|
|||||||
"by_type": by_type,
|
"by_type": by_type,
|
||||||
"by_priority": by_priority,
|
"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
|
||||||
|
|||||||
Reference in New Issue
Block a user