grantforge-api / backend /endpoints /regulation.py
GrantForge Bot
Deploy sha-565ad85979610064f6d1c18ab3b6404357d61073 — source build (no GHCR)
ce8f04a
Raw
History Blame Contribute Delete
1.5 kB
"""Regulation API — schema registry and structured rules."""
from __future__ import annotations
from typing import Any, Optional
from fastapi import APIRouter, Depends, HTTPException, Query
from pydantic import BaseModel, Field
from core.regulation.schema_registry import get_all_schemas, get_schema, list_schema_ids
from core.search.regulation_engine import regulation_engine
from core.subscription.middleware import verify_token
router = APIRouter(prefix="/api/regulation", tags=["regulation"])
class StructuredRulesResponse(BaseModel):
program: str
rules: dict[str, Any]
@router.get("/schemas")
async def regulation_schemas(
schema_id: Optional[str] = Query(None, description="Opcjonalny identyfikator schematu"),
token_data: dict = Depends(verify_token),
):
_ = token_data
if schema_id:
schema = get_schema(schema_id)
if not schema:
raise HTTPException(status_code=404, detail=f"Nieznany schemat: {schema_id}")
return {"schema_id": schema_id, "schema": schema}
return {
"schema_ids": list_schema_ids(),
"schemas": get_all_schemas(),
}
@router.get("/structured-rules/{program_name}", response_model=StructuredRulesResponse)
async def structured_rules_for_program(
program_name: str,
token_data: dict = Depends(verify_token),
):
_ = token_data
rules = regulation_engine.get_structured_rules_for_program(program_name)
return StructuredRulesResponse(program=program_name, rules=rules)