Fleshout some of the notifcation service

This is probably organized incorrectly. If it's a service it should
be grouped with the other services
This commit is contained in:
Campbell Alden 2026-08-01 01:09:20 +09:00
parent 0b3b6f50fe
commit 6700bc9763

View file

@ -1,12 +1,55 @@
from typing import Any
from .data import Notification
import abc import abc
from typing import Any
from src.services.email import EmailService
from src.config import Config
from .data import Notification
# MUSTFIX: Needs real users!
class NotificationService(abc.ABC): class NotificationSender(abc.ABC):
"""A service that sends notifications to the user""" """A service that sends notifications to the user"""
def __init__(self, name: str):
self._name = name
@property
def name(self):
return self._name
@abc.abstractmethod @abc.abstractmethod
def notify(self, user: Any, notification: Notification): def notify(self, user: Any, notification: Notification):
"""Send a notification""" """Send a notification"""
pass pass
class NotificationService:
def __init__(self):
self._senders = []
def register_sender(self, sender: NotificationSender):
self._senders.append(sender)
def notify_user(self, user: Any, notification: Notification):
for s in self._senders:
if s.name in user.notification_methods:
s.notify(user, notification)
class EmailNotifier(NotificationSender):
def __init__(self, email_service: EmailService):
super().__init__('email')
self._email_service = email_service
def notify(self, user: Any, notification: Notification):
# TODO: Convert notification and user information into an EmailDTO for the email service
pass
def make_notification_service(email_service: EmailService):
service = NotificationService()
service.register_sender(EmailNotifier(email_service))
return service