Files
LLM-infa/api_legacy/db/user.py
jze9 2697e01714 Рабочий пайплайн: YouTube -> транскрипция -> выжимка -> Postgres
- новый api/: /pipeline/process (yt-dlp, субтитры или Vosk, LLM/экстрактивная
  суммаризация), /videos, /llm; старый код перенесён в api_legacy/
- web/: Flet UI (flet 0.28.3 + flet-web, порт 8550)
- Dockerfile.api: ffmpeg слоем из mwader/static-ffmpeg, pip с кэш-маунтом
- requirements/pyproject: убраны moviepy, imageio-ffmpeg, битый asyncio
- README с инструкцией запуска и загрузкой Vosk-модели

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 11:12:46 +05:00

65 lines
1.9 KiB
Python

from api.db.connection import SessionLocal
from api.models.user import User
from sqlalchemy import select
import uuid
async def create_user(telegram_id: str, name: str | None = None):
async with SessionLocal() as session:
# ensure no NULL in DB: replace None with empty string
safe_name = name if name is not None else ""
user = User(id=str(uuid.uuid4()), telegram_id=telegram_id, name=safe_name)
session.add(user)
await session.commit()
await session.refresh(user)
return user
async def get_user(user_id: str):
async with SessionLocal() as session:
q = select(User).where(User.id == user_id)
res = await session.execute(q)
return res.scalars().first()
async def get_user_by_telegram(telegram_id: str):
async with SessionLocal() as session:
q = select(User).where(User.telegram_id == telegram_id)
res = await session.execute(q)
return res.scalars().first()
async def update_user(user_id: str, name: str | None = None):
async with SessionLocal() as session:
q = select(User).where(User.id == user_id)
res = await session.execute(q)
user = res.scalars().first()
if not user:
return None
if name is not None:
# replace None handled by caller; here update only when provided
user.name = name
await session.commit()
return user
async def delete_user(user_id: str):
async with SessionLocal() as session:
q = select(User).where(User.id == user_id)
res = await session.execute(q)
user = res.scalars().first()
if not user:
return False
await session.delete(user)
await session.commit()
return True
async def list_users():
async with SessionLocal() as session:
q = select(User)
res = await session.execute(q)
return res.scalars().all()