from .. import reports
# Import the main app
+from . import require_api_key
from . import app
from . import backend
+class CreateReport(pydantic.BaseModel):
+ # List
+ list: str
+
+ # Domain
+ name: str
+
+ # Comment
+ comment: str = ""
+
+ # Block?
+ block: bool = True
+
+
# Create a router
router = fastapi.APIRouter(
prefix="/reports",
async def get_reports() -> typing.List[reports.Report]:
return [l async for l in backend.reports]
+@router.post("")
+async def create_report(
+ report: CreateReport,
+ user = fastapi.Depends(require_api_key),
+) -> reports.Report:
+ # Fetch the list
+ list = await backend.lists.get_by_slug(report.list)
+ if not list:
+ raise fastapi.HTTPException(400, "Could not find list '%s'" % report.list)
+
+ # Create the report
+ return await list.report(
+ name = report.name,
+ reported_by = user,
+ comment = report.comment,
+ block = report.block,
+ )
+
@router.get("/{id}")
async def get_report(report = fastapi.Depends(get_report_from_path)) -> reports.Report:
return report