From f23caa3809d14f5271041f21fd09a0cc6bc098e4 Mon Sep 17 00:00:00 2001 From: Andrey Kugubaev Date: Wed, 5 Jul 2023 00:06:55 +0200 Subject: [PATCH] send notifications ver 1.1 --- src/api/endpoints/tasks.py | 10 +++------- src/core/services/notification.py | 10 +++++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api/endpoints/tasks.py b/src/api/endpoints/tasks.py index f10c39ad..89dd724a 100644 --- a/src/api/endpoints/tasks.py +++ b/src/api/endpoints/tasks.py @@ -2,6 +2,7 @@ from src.api.schemas import TaskRequest, TaskResponse from src.api.services import TaskService +from src.bot.bot import create_bot from src.core.db.models import Task from src.core.services.notification import TelegramNotification from src.core.utils import display_tasks @@ -13,15 +14,10 @@ async def actualize_tasks( tasks: list[TaskRequest], task_service: TaskService = Depends(), + notifications_services: TelegramNotification = Depends(create_bot), ) -> None: await task_service.actualize_objects(tasks, Task) - - -@task_router.post("/", description="Уведомление о новых задачах") -async def send_notifications( - notifications_services: TelegramNotification = Depends(), -) -> None: - await notifications_services.send_notification(display_tasks) + await notifications_services.send_notification(message=display_tasks) @task_router.get( diff --git a/src/core/services/notification.py b/src/core/services/notification.py index 29d354a8..8427477e 100644 --- a/src/core/services/notification.py +++ b/src/core/services/notification.py @@ -39,12 +39,20 @@ async def send_messages( self.__bot_application.create_task(asyncio.gather(*send_message_tasks)) return True - async def send_notification( + async def send_notifications( self, message: str, ): """Делает массовую рассылку уведомления о новых задачах пользователям users.""" + users = AbstractRepository.get_all(User) + for user in users: + self.__send_message(user.telegram_id, message) + async def send_notification( + self, + message: str, + ): + """Делает массовую рассылку уведомления о новых задачах пользователям users.""" users = AbstractRepository.get_all(User) for user in users: self.__send_message(user.telegram_id, message)