diff --git a/app/bot/fsm_contexts/feedback_context.py b/app/bot/fsm_contexts/feedback_context.py index 1222dc7..fcb5d0d 100644 --- a/app/bot/fsm_contexts/feedback_context.py +++ b/app/bot/fsm_contexts/feedback_context.py @@ -10,9 +10,9 @@ from helpers import ask_next_question, start_inactivity_timer, get_user_id from loggers.log import setup_logging from bot.validators import is_valid_rating -from crud.feedback import create_feedback from crud.users import get_id_by_tg_id from core.bot_setup import bot +from crud.feedback_crud import feedback_crud router = Router() @@ -81,7 +81,7 @@ async def process_description( feedback_data = await state.get_data() - await create_feedback(feedback_data, session) + await feedback_crud.create(feedback_data, session) logger.info(f'Запись создана в БД с ID: {feedback_data.get("user")}.') diff --git a/app/crud/feedback.py b/app/crud/feedback.py deleted file mode 100644 index 386ab4c..0000000 --- a/app/crud/feedback.py +++ /dev/null @@ -1,17 +0,0 @@ -from datetime import datetime - -from sqlalchemy.ext.asyncio import AsyncSession - -from models.models import Feedback - - -async def create_feedback(user_data: dict, session: AsyncSession) -> Feedback: - """Создание записи с отзывом.""" - - data_to_db = Feedback(**user_data, feedback_date=datetime.utcnow()) - - session.add(data_to_db) - await session.commit() - await session.refresh(data_to_db) - - return data_to_db diff --git a/app/crud/feedback_crud.py b/app/crud/feedback_crud.py index 51d68b3..104844e 100644 --- a/app/crud/feedback_crud.py +++ b/app/crud/feedback_crud.py @@ -13,15 +13,5 @@ async def get_multi(self, session: AsyncSession): ) return db_objs.scalars().all() - async def bulk_create( - self, - objs_in: list, - session: AsyncSession, - ): - db_objs = [self.model(**obj) for obj in objs_in] - session.add_all(db_objs) - await session.commit() - return db_objs - feedback_crud = FeedbackCRUD(Feedback) diff --git a/app/main.py b/app/main.py index e869d9e..32e26b1 100644 --- a/app/main.py +++ b/app/main.py @@ -30,14 +30,16 @@ async def main() -> None: dispatcher.include_router(fsm_context_router) dispatcher.include_router(feedback_context) - dispatcher.include_router(message_router) - dispatcher.include_router(callback_router) dispatcher.include_router(admin_router) dispatcher.include_router(user_router) + dispatcher.include_router(message_router) + dispatcher.include_router(callback_router) try: logger.info("Запуск бота...") - dispatcher.update.middleware(DataBaseSession(session_pool=AsyncSessionLocal)) + dispatcher.update.middleware( + DataBaseSession(session_pool=AsyncSessionLocal) + ) await add_portfolio() await set_admin() await dispatcher.start_polling(bot) diff --git a/app/test.py b/app/test.py deleted file mode 100644 index 7f8f998..0000000 --- a/app/test.py +++ /dev/null @@ -1,23 +0,0 @@ -import asyncio -from datetime import datetime - -from core.db import AsyncSessionLocal -from crud.feedback_crud import feedback_crud - - - -feedbacks = { - "user": 1, - "feedback_text": "Типа отзыв", - "feedback_date": datetime.now(), - "rating": 5 - -} - -async def add_to_db(): - async with AsyncSessionLocal() as session: - await feedback_crud.create(feedbacks, session) - - -if __name__ == "__main__": - asyncio.run(add_to_db()) \ No newline at end of file