58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
"""Notification service"""
|
|
|
|
from typing import Optional
|
|
from sqlalchemy.orm import Session
|
|
from app.db.models import Family
|
|
|
|
|
|
class NotificationService:
|
|
"""Service for managing notifications"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def should_notify(self, family: Family, notification_type: str) -> bool:
|
|
"""Check if notification should be sent based on family settings"""
|
|
if family.notification_level == "none":
|
|
return False
|
|
elif family.notification_level == "important":
|
|
return notification_type in ["budget_exceeded", "goal_completed"]
|
|
else: # all
|
|
return True
|
|
|
|
def format_transaction_notification(
|
|
self, user_name: str, amount: float, category: str, account: str
|
|
) -> str:
|
|
"""Format transaction notification message"""
|
|
return (
|
|
f"💰 {user_name} добавил запись:\n"
|
|
f"Сумма: {amount}₽\n"
|
|
f"Категория: {category}\n"
|
|
f"Счет: {account}"
|
|
)
|
|
|
|
def format_budget_warning(
|
|
self, budget_name: str, spent: float, limit: float, percent: float
|
|
) -> str:
|
|
"""Format budget warning message"""
|
|
return (
|
|
f"⚠️ Внимание по бюджету!\n"
|
|
f"Бюджет: {budget_name}\n"
|
|
f"Потрачено: {spent}₽ из {limit}₽\n"
|
|
f"Превышено на: {percent:.1f}%"
|
|
)
|
|
|
|
def format_goal_progress(
|
|
self, goal_name: str, current: float, target: float, percent: float
|
|
) -> str:
|
|
"""Format goal progress message"""
|
|
return (
|
|
f"🎯 Прогресс цели: {goal_name}\n"
|
|
f"Накоплено: {current}₽ из {target}₽\n"
|
|
f"Прогресс: {percent:.1f}%"
|
|
)
|
|
|
|
def format_goal_completed(self, goal_name: str) -> str:
|
|
"""Format goal completion message"""
|
|
return f"✅ Цель достигнута! 🎉\n{goal_name}"
|