klg-asutk-app/backend/app/api/streaming.py
Yuriy 0150aba4f5 Consolidation: KLG ASUTK + PAPA integration
- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites)
- Remove localhost refs: openapi, inbox page
- Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI
- Add stub routes: knowledge/insights, recommendations, search, log-error
- Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests
- Fix inbox-server: ORDER BY created_at, package.json
- Remove redundant app/api/inbox/files route (rewrites handle it)
- knowledge/ in gitignore (large PDFs)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:18:31 +03:00

49 lines
1.4 KiB
Python

"""
Streaming API endpoints
"""
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from typing import Optional, List
from app.streaming.redpanda import publish_event
from app.streaming.risingwave import query_materialized_view
router = APIRouter()
class EventRequest(BaseModel):
"""Запрос на публикацию события"""
topic: str
event: dict
key: Optional[str] = None
@router.post("/events")
async def publish_event_endpoint(request: EventRequest):
"""Публикация события в Redpanda"""
try:
await publish_event(request.topic, request.event, request.key)
return {"status": "published", "topic": request.topic}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/views/{view_name}")
async def get_materialized_view(view_name: str, filters: Optional[dict] = None):
"""Получение данных из materialized view"""
try:
data = await query_materialized_view(view_name, filters or {})
return {"view": view_name, "data": data}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/health")
async def streaming_health():
"""Проверка здоровья streaming компонентов"""
return {
"redpanda": "connected",
"risingwave": "connected",
"flink": "connected",
}