Files
linkedstorm/app/api/routes/speakers.py
T
pluto 59014f6fe7 feat: API routes — speakers, rooms, search, RAG
Full implementations replacing stubs: speakers CRUD with utterance count,
rooms list + mute/unmute via pipeline, FTS5-based search, RAG /ask and
/summary endpoints. 15 route tests (8 new) all passing; 35 total.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-28 10:46:24 -05:00

35 lines
997 B
Python

import sqlite3
from fastapi import APIRouter
from pydantic import BaseModel
class CreateSpeakerRequest(BaseModel):
name: str
def make_router(settings, db_factory):
router = APIRouter(prefix="/api/speakers")
@router.get("")
def list_speakers():
db: sqlite3.Connection = db_factory()
rows = db.execute("""
SELECT s.id, s.name, s.created_at,
COUNT(u.id) as utterance_count
FROM speakers s
LEFT JOIN utterances u ON u.speaker_id = s.id
GROUP BY s.id
ORDER BY s.name
""").fetchall()
return [dict(r) for r in rows]
@router.post("")
def create_speaker(body: CreateSpeakerRequest):
db: sqlite3.Connection = db_factory()
cur = db.execute("INSERT INTO speakers (name) VALUES (?)", (body.name,))
db.commit()
row = db.execute("SELECT * FROM speakers WHERE id=?", (cur.lastrowid,)).fetchone()
return dict(row)
return router