###############################################################################
import fastapi
+import pydantic
import typing
import uuid
"""
Fetches a report by its ID
"""
- return backend.reports.get_by_id(id)
+ # Fetch the report
+ report = backend.reports.get_by_id(id)
+
+ # Raise 404 if we could not find the report
+ if not report:
+ raise fastapi.HTTPException(404, "Could not find report %s" % id)
+
+ return report
@router.get("")
def get_reports() -> typing.List[reports.Report]:
@router.get("/{id}")
def get_report(report = fastapi.Depends(get_report_from_path)) -> reports.Report:
- if not report:
- raise fastapi.HTTPException(404, "Could not find report")
-
return report
+class CloseReport(pydantic.BaseModel):
+ # Closed By
+ closed_by: str
+
+ # Accept?
+ accept: bool = True
+
+@router.post("/{id}/close")
+def close_report(
+ data: CloseReport,
+ report: reports.Report = fastapi.Depends(get_report_from_path),
+) -> fastapi.Response:
+ # Close the report
+ with backend.db:
+ report.close(
+ closed_by = data.closed_by,
+ accept = data.accept,
+ )
+
+ # Send 204
+ return fastapi.Response(status_code=fastapi.status.HTTP_204_NO_CONTENT)
+
# Include our endpoints
app.include_router(router)
if self.closed_by:
raise RuntimeError("Report %s has already been closed" % self)
+ # XXX Check for permissions
+
# Mark this report as closed
self.closed_at = sqlmodel.func.current_timestamp()
self.closed_by = closed_by