Skip to content

Commit

Permalink
send notifications ver 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey-Kugubaev committed Jun 28, 2023
1 parent a3899ab commit eaf07bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/api/endpoints/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions src/core/services/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)

0 comments on commit eaf07bf

Please sign in to comment.