from sqlalchemy import select from api.db.connection import SessionLocal from api.models.video import Video async def create_video( *, uuid: str, source_url: str, title: str, video_path: str, text_full_path: str, text_summary_path: str, transcription_method: str, ) -> Video: async with SessionLocal() as session: v = Video( uuid=uuid, source_url=source_url, title=title or "", video_path=video_path or "", text_full_path=text_full_path or "", text_summary_path=text_summary_path or "", transcription_method=transcription_method or "", ) session.add(v) await session.commit() await session.refresh(v) return v async def get_video(video_uuid: str) -> Video | None: async with SessionLocal() as session: res = await session.execute(select(Video).where(Video.uuid == video_uuid)) return res.scalars().first() async def list_videos() -> list[Video]: async with SessionLocal() as session: res = await session.execute(select(Video).order_by(Video.created_at.desc())) return list(res.scalars().all()) async def delete_video(video_uuid: str) -> bool: async with SessionLocal() as session: res = await session.execute(select(Video).where(Video.uuid == video_uuid)) v = res.scalars().first() if not v: return False await session.delete(v) await session.commit() return True