Skip to content

Commit

Permalink
send notifications ver 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey-Kugubaev committed Jul 4, 2023
1 parent eaf07bf commit f23caa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/api/endpoints/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion src/core/services/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f23caa3

Please sign in to comment.