routers: extract chat + ops from api.py
api.py was 933 lines mixing four distinct concerns: indicators + news + strategic log (the JSON/HTMX API proper), the chat endpoint + its three private helpers (~200 lines), and the two HTML-only ops endpoints /markets-bar + /health (~150 lines). Extracted: - app/routers/chat.py — POST /api/chat + _latest_quotes_by_group_chat, _thesis_headlines_for_chat, _month_spend - app/routers/ops.py — GET /api/markets-bar + GET /api/health + _fmt_price helper Both new routers use the same dependencies=[Depends(require_token)] as api.py and are mounted at the /api prefix in app/main.py. URL surface is byte-identical with no externally-visible change. api.py shrinks to ~620 lines focused on indicators+news+log+settings. Helpers shared with the original api.py (_md_to_html, _resolve_tone_param) are imported from app.routers.api where needed in chat.py to avoid duplication. Also updated tests/test_chat_and_log_gates.py to mount chat_router in its local test app, since /api/chat now lives there. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
b055eea1c2
commit
833d1775ab
5 changed files with 364 additions and 322 deletions
|
|
@ -23,6 +23,7 @@ def _build_app(tmp_path):
|
|||
from app.db import Base
|
||||
from app.models import StrategicLog, User
|
||||
from app.routers import api as api_router
|
||||
from app.routers import chat as chat_router
|
||||
|
||||
engine = create_async_engine(f"sqlite+aiosqlite:///{tmp_path}/gates.db")
|
||||
factory = async_sessionmaker(engine, expire_on_commit=False)
|
||||
|
|
@ -56,6 +57,7 @@ def _build_app(tmp_path):
|
|||
|
||||
app = FastAPI()
|
||||
app.include_router(api_router.router, prefix="/api")
|
||||
app.include_router(chat_router.router, prefix="/api")
|
||||
client = TestClient(app)
|
||||
return client, sign_session(1), sign_session(2)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue