bot rafactor and bugfix
This commit is contained in:
24
app/bots/editor/templates.py
Normal file
24
app/bots/editor/templates.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Функции для работы с шаблонами."""
|
||||
from __future__ import annotations
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
from app.db.session import async_session_maker
|
||||
from app.models.templates import Template
|
||||
|
||||
|
||||
async def list_templates(owner_id: Optional[int] = None):
|
||||
"""Получение списка шаблонов."""
|
||||
async with async_session_maker() as session:
|
||||
stmt = select(Template)
|
||||
if owner_id:
|
||||
stmt = stmt.filter(Template.owner_id == owner_id)
|
||||
result = await session.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def create_template(template_data: dict):
|
||||
"""Создание нового шаблона."""
|
||||
async with async_session_maker() as session:
|
||||
template = Template(**template_data)
|
||||
session.add(template)
|
||||
await session.commit()
|
||||
Reference in New Issue
Block a user