Files
yunke/yunke-server/app/api/main.py
T
浅念 1e0467b40f feat: customer list API
Minimal read-only FastAPI surface over the mirrored DB:
- GET /api/customers with pagination (page/page_size) and optional
  channel / owner_account_id / department_id filters, ordered by
  last_chat_time desc (nulls last) then friend_id.
- GET /api/health liveness probe.
- Pydantic v2 CustomerOut + generic Page[T] envelope.
- CORS configured permissively for the local frontend.
- Tests override get_session to an in-memory async SQLite session
  (StaticPool) and drive the app via httpx ASGITransport.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-01 12:10:03 +08:00

38 lines
893 B
Python

"""FastAPI app for the yunke data-mirror viewing API.
Run locally with::
uvicorn app.api.main:app --reload
Includes:
* ``GET /api/health`` -> ``{"status": "ok"}`` liveness probe.
* ``GET /api/customers`` (see :mod:`app.api.routers.customer`).
CORS is configured permissively (wildcard origin, no credentials) so the local
frontend can call the API during development. Auth / finer CORS are LATER tasks.
"""
from __future__ import annotations
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.routers import customer
app = FastAPI(title="yunke data mirror")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(customer.router)
@app.get("/api/health")
async def health() -> dict[str, str]:
"""Trivial liveness probe."""
return {"status": "ok"}