From: Michael Tremer Date: Mon, 2 Mar 2026 17:56:29 +0000 (+0000) Subject: api: Create a new endpoint to submit reports X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e415ff9b6e5f499fb11b07e569705329bc85632f;p=dbl.git api: Create a new endpoint to submit reports This makes the API slightly cleaner and moves all report things together. Signed-off-by: Michael Tremer --- diff --git a/src/dbl/api/reports.py b/src/dbl/api/reports.py index 8f0e340..4853dda 100644 --- a/src/dbl/api/reports.py +++ b/src/dbl/api/reports.py @@ -26,9 +26,24 @@ import uuid 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", @@ -52,6 +67,24 @@ async def get_report_from_path(id: uuid.UUID = fastapi.Path(...)) -> reports.Rep 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