integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Generic paginated read access to every importable table through its
|
||||
`Repository`, so clients can inspect what an import wrote."""
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from webapi.imports.schemas.registry import ENTITY_REGISTRY
|
||||
|
||||
data_bp = Blueprint("data", __name__)
|
||||
|
||||
_MAX_PAGE = 500
|
||||
|
||||
|
||||
@data_bp.get("/<target>")
|
||||
def list_rows(target: str):
|
||||
spec = ENTITY_REGISTRY.get(target)
|
||||
if spec is None:
|
||||
return jsonify({"error": f"unknown target: {target!r}"}), 404
|
||||
try:
|
||||
limit = min(max(int(request.args.get("limit", 50)), 1), _MAX_PAGE)
|
||||
offset = max(int(request.args.get("offset", 0)), 0)
|
||||
except ValueError:
|
||||
return jsonify({"error": "limit/offset must be integers"}), 400
|
||||
rows = spec.repository.list(limit=limit, offset=offset)
|
||||
return jsonify(
|
||||
{
|
||||
"target": target,
|
||||
"total": spec.repository.count(),
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
# Table order (JSON objects get their keys sorted on the way out).
|
||||
"columns": [column.name for column in spec.model.__table__.columns],
|
||||
"rows": [row.model_dump() for row in rows],
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user