-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into refactoring/tasks
- Loading branch information
Showing
13 changed files
with
138 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
### **Why?** | ||
|
||
*Зачем выполняется реализация задачи и какую проблему она решает.* | ||
|
||
### **How To Do?** | ||
|
||
*Как мы выполняем реализацию данной задачи, какие действия нужны для достижения цели.* | ||
|
||
### **Where?** | ||
|
||
*Где делаем реализацию задачи, какие сервисы задействованы, ссылка на требования, сcылка на API, скриншоты.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
from .categories import category_router | ||
from .form import form_router | ||
from .notification import users_group_notification_router | ||
from .tasks import task_router | ||
|
||
__all__ = ("category_router", "task_router", "form_router") | ||
__all__ = ( | ||
"category_router", | ||
"task_router", | ||
"form_router", | ||
"users_group_notification_router", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from fastapi import APIRouter, Depends | ||
|
||
from src.api.schemas import TelegramNotificationRequest | ||
from src.api.services.messages import TelegramNotificationService | ||
|
||
users_group_notification_router = APIRouter() | ||
|
||
|
||
@users_group_notification_router.post( | ||
"/", | ||
description="Сообщение для группы пользователей", | ||
) | ||
async def send_telegram_notification( | ||
notifications: TelegramNotificationRequest, | ||
telegram_notification_service: TelegramNotificationService = Depends(), | ||
) -> None: | ||
"""Отправляет сообщение указаной группе пользователей""" | ||
await telegram_notification_service.send_messages_to_group_of_users(notifications) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from fastapi import APIRouter | ||
|
||
from src.api.endpoints import category_router, form_router, task_router | ||
from src.api.endpoints import category_router, form_router, task_router, users_group_notification_router | ||
from src.settings import settings | ||
|
||
api_router = APIRouter(prefix=settings.ROOT_PATH) | ||
api_router.include_router(category_router, prefix="/categories", tags=["Categories"]) | ||
api_router.include_router(task_router, prefix="/tasks", tags=["Tasks"]) | ||
api_router.include_router(form_router, prefix="/telegram", tags=["Forms"]) | ||
api_router.include_router(users_group_notification_router, prefix="/messages", tags=["Messages"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from fastapi import Depends | ||
from sqlalchemy import select | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from telegram.ext import Application | ||
|
||
from src.bot.bot import create_bot | ||
from src.core.db import get_session | ||
from src.core.db.models import User | ||
from src.core.enums import TelegramNotificationUsersGroups | ||
from src.core.services.notification import TelegramNotification | ||
|
||
|
||
class TelegramNotificationService: | ||
"""Класс описывающий функционал передачи сообщения | ||
определенному пользователю""" | ||
|
||
def __init__( | ||
self, | ||
telegram_bot: Application = Depends(create_bot), | ||
session: AsyncSession = Depends(get_session), | ||
) -> None: | ||
self._session = session | ||
self.telegram_notification = TelegramNotification(telegram_bot) | ||
|
||
async def send_messages_to_group_of_users(self, notifications): | ||
"""Отправляет сообщение указанной группе пользователей""" | ||
match notifications.mode.upper(): | ||
case TelegramNotificationUsersGroups.ALL.name: | ||
users = await self._session.scalars(select(User)) | ||
case TelegramNotificationUsersGroups.SUBSCRIBED.name: | ||
users = await self._session.scalars(select(User).where(User.has_mailing == True)) # noqa | ||
case TelegramNotificationUsersGroups.UNSUBSCRIBED.name: | ||
users = await self._session.scalars(select(User).where(User.has_mailing == False)) # noqa | ||
await self.telegram_notification.send_messages(message=notifications.message, users=users) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROCHARITY_URL = "https://procharity.ru/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.