from fastapi import APIRouter from pydantic import BaseModel from sqlalchemy import select from app.api.deps import ApiUser, DbSession from app.models import User router = APIRouter(prefix="/users", tags=["users"]) class UserName(BaseModel): id: int username: str @router.get("/me", response_model=UserName) def me(user: ApiUser) -> UserName: """Who a token belongs to (e.g. so the agent only takes over its owner's clips).""" return UserName(id=user.id, username=user.username) @router.get("", response_model=list[UserName]) def list_user_names(user: ApiUser, db: DbSession) -> list[UserName]: """Names of the other active users, for sharing projects; nothing else is revealed.""" rows = db.execute( select(User.id, User.username) .where(User.is_active, User.id != user.id) .order_by(User.username) ) return [UserName(id=uid, username=name) for uid, name in rows]