diff --git a/src/api/endpoints/tasks.py b/src/api/endpoints/tasks.py index 2abd6047..f10c39ad 100644 --- a/src/api/endpoints/tasks.py +++ b/src/api/endpoints/tasks.py @@ -2,7 +2,7 @@ from src.api.schemas import TaskRequest, TaskResponse from src.api.services import TaskService -from src.core.db.models import Task, User +from src.core.db.models import Task from src.core.services.notification import TelegramNotification from src.core.utils import display_tasks @@ -13,10 +13,15 @@ async def actualize_tasks( tasks: list[TaskRequest], task_service: TaskService = Depends(), - notifications_services: TelegramNotification = Depends(), ) -> None: await task_service.actualize_objects(tasks, Task) - await notifications_services.send_messages(display_tasks, User) + + +@task_router.post("/", description="Уведомление о новых задачах") +async def send_notifications( + notifications_services: TelegramNotification = Depends(), +) -> None: + await notifications_services.send_notification(display_tasks) @task_router.get( diff --git a/src/core/services/notification.py b/src/core/services/notification.py index 4e9f79f7..29d354a8 100644 --- a/src/core/services/notification.py +++ b/src/core/services/notification.py @@ -5,6 +5,7 @@ from telegram.ext import Application from src.core.db.models import User +from src.core.db.repository.base import AbstractRepository logger = logging.getLogger(__name__) @@ -37,3 +38,13 @@ async def send_messages( send_message_tasks = (self.__send_message(user.telegram_id, message) for user in users) self.__bot_application.create_task(asyncio.gather(*send_message_tasks)) return True + + async def send_notification( + self, + message: str, + ): + """Делает массовую рассылку уведомления о новых задачах пользователям users.""" + + users = AbstractRepository.get_all(User) + for user in users: + self.__send_message(user.telegram_id, message)