Support-BOT

This commit is contained in:
2024-05-01 19:55:22 +03:00
commit 4280385d32
34 changed files with 1361 additions and 0 deletions

0
app/core/__init__.py Normal file
View File

3
app/core/base.py Normal file
View File

@@ -0,0 +1,3 @@
"""Импорты класса Base и всех моделей для Alembic."""
from app.core.db import Base # noqa
from app.models import User, Message # noqa

29
app/core/config.py Normal file
View File

@@ -0,0 +1,29 @@
import os
from typing import Optional
from pydantic import BaseSettings
from dotenv import load_dotenv
load_dotenv()
class Settings(BaseSettings):
TELEGRAM_TOKEN: str
GROUP_ID: str
WEBHOOK_DOMAIN: Optional[str]
WEBHOOK_PATH: Optional[str]
APP_HOST: str
APP_PORT: int
DATABASE_URL: str
DB_HOST: str
DB_PORT: str
DB_USER: str = os.getenv('POSTGRES_USER')
DB_PASSWORD: str = os.getenv('POSTGRES_PASSWORD')
START_MESSAGE: str = os.getenv('START_MESSAGE')
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
settings = Settings()

36
app/core/db.py Normal file
View File

@@ -0,0 +1,36 @@
from sqlalchemy import Integer, TIMESTAMP, func
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import declared_attr, declarative_base, sessionmaker, \
mapped_column
from app.core.config import settings
class PreBase:
"""Абстрактная модель для наследования"""
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
id = mapped_column(Integer, primary_key=True)
created_at = mapped_column(TIMESTAMP,
server_default=func.current_timestamp(),
nullable=False)
updated_at = mapped_column(TIMESTAMP,
server_default=func.current_timestamp(),
nullable=False,
onupdate=func.current_timestamp())
Base = declarative_base(cls=PreBase)
engine = create_async_engine(settings.DATABASE_URL)
AsyncSessionLocal = sessionmaker(engine, class_=AsyncSession)
async def get_async_session():
"""Генератор асинхронной сессии"""
async with AsyncSessionLocal() as async_session_gen:
yield async_session_gen