bot rafactor and bugfix

This commit is contained in:
2025-08-19 04:45:16 +09:00
parent 43dda889f8
commit a8d860ed87
31 changed files with 4396 additions and 613 deletions

View File

@@ -1,77 +1,3 @@
# # app/api/routes/templates.py
# from __future__ import annotations
# from fastapi import APIRouter, Depends, HTTPException, Query
# from sqlalchemy import select, or_
# from sqlalchemy.ext.asyncio import AsyncSession
# from app.db.session import get_async_session
# from app.models.templates import Template
# from app.api.schemas.template import TemplateIn, TemplateOut
# from app.services.templates import count_templates
# router = APIRouter(prefix="/templates", tags=["templates"])
# # Заглушка аутентификации
# async def get_owner_id(x_user_id: int | None = None):
# return x_user_id or 0
# @router.post("/", response_model=TemplateOut)
# async def create_tpl(
# data: TemplateIn,
# owner_id: int = Depends(get_owner_id),
# s: AsyncSession = Depends(get_async_session),
# ):
# tpl = Template(owner_id=owner_id, **data.model_dump())
# s.add(tpl)
# await s.commit()
# await s.refresh(tpl)
# return tpl
# @router.get("/", response_model=list[TemplateOut])
# async def list_tpls(
# owner_id: int = Depends(get_owner_id),
# limit: int = Query(20, ge=1, le=100),
# offset: int = Query(0, ge=0),
# q: str | None = Query(default=None),
# s: AsyncSession = Depends(get_async_session),
# ):
# stmt = select(Template).where(
# Template.owner_id == owner_id,
# Template.is_archived.is_(False),
# )
# if q:
# like = f"%{q}%"
# stmt = stmt.where(or_(Template.name.ilike(like), Template.title.ilike(like)))
# stmt = stmt.order_by(Template.updated_at.desc()).limit(limit).offset(offset)
# res = await s.execute(stmt)
# return list(res.scalars())
# @router.get("/count")
# async def count_tpls(
# owner_id: int = Depends(get_owner_id),
# q: str | None = None,
# ):
# total = await count_templates(owner_id, q)
# return {"total": total}
# @router.delete("/{tpl_id}")
# async def delete_tpl(
# tpl_id: int,
# owner_id: int = Depends(get_owner_id),
# s: AsyncSession = Depends(get_async_session),
# ):
# res = await s.execute(select(Template).where(
# Template.id == tpl_id,
# Template.owner_id == owner_id
# ))
# tpl = res.scalars().first()
# if not tpl:
# raise HTTPException(404, "not found")
# await s.delete(tpl)
# await s.commit()
# return {"ok": True}
# app/api/routes/templates.py
from __future__ import annotations
from fastapi import APIRouter, Depends, HTTPException, Query