feat: enrich member/comment/propose APIs with usernames
- ProjectMemberResponse now includes username and full_name - Comment list endpoint returns author_username - ProposeResponse now includes created_by_username - All serializers resolve User objects to surface human-readable names - Supports frontend code-first migration (TODO §3.1/3.2)
This commit is contained in:
@@ -50,9 +50,22 @@ def create_comment(comment: schemas.CommentCreate, db: Session = Depends(get_db)
|
||||
return db_comment
|
||||
|
||||
|
||||
@router.get("/tasks/{task_id}/comments", response_model=List[schemas.CommentResponse])
|
||||
@router.get("/tasks/{task_id}/comments")
|
||||
def list_comments(task_id: int, db: Session = Depends(get_db)):
|
||||
return db.query(models.Comment).filter(models.Comment.task_id == task_id).all()
|
||||
comments = db.query(models.Comment).filter(models.Comment.task_id == task_id).all()
|
||||
result = []
|
||||
for c in comments:
|
||||
author = db.query(models.User).filter(models.User.id == c.author_id).first()
|
||||
result.append({
|
||||
"id": c.id,
|
||||
"content": c.content,
|
||||
"task_id": c.task_id,
|
||||
"author_id": c.author_id,
|
||||
"author_username": author.username if author else None,
|
||||
"created_at": c.created_at,
|
||||
"updated_at": c.updated_at,
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
@router.patch("/comments/{comment_id}", response_model=schemas.CommentResponse)
|
||||
|
||||
Reference in New Issue
Block a user