accept: bool = True
+class Comment(pydantic.BaseModel):
+ # Comment
+ comment: str
+
+
# Create a router
router = fastapi.APIRouter(
prefix="/reports",
) -> list[reports.ReportComment]:
return [comment async for comment in report.get_comments()]
+@router.post("/{id}/comments")
+async def submit_comment(
+ comment: Comment,
+ report: reports.Report = fastapi.Depends(get_report_from_path),
+ user: users.User = fastapi.Depends(require_current_user),
+) -> reports.ReportComment:
+ """
+ Posts a comment to a report
+ """
+ # Fail if the report has already been closed
+ if report.is_closed():
+ raise fastapi.HTTPException(409, "The report is closed and cannot receive any comments")
+
+ # Create the comment
+ return await report.comment(comment=comment.comment, reporter=user)
+
# Include our endpoints
app.include_router(router)
"""
Posts a new comment to this report
"""
+ if isinstance(reporter, users.User):
+ reporter = reporter.uid
+
# Write the comment to the database
comment = await self.backend.db.insert(
ReportComment,
points = points,
)
+ # Manifest the object in the database immediately to assign the ID
+ await self.backend.db.flush_and_refresh(comment)
+
# Send a notification about this comment
if notify:
pass # XXX TODO