From 6700bc97633173fd60d18b1de452e06ac2d04662 Mon Sep 17 00:00:00 2001 From: Campbell Alden Date: Sat, 1 Aug 2026 01:09:20 +0900 Subject: [PATCH] Fleshout some of the notifcation service This is probably organized incorrectly. If it's a service it should be grouped with the other services --- src/notifications/service.py | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/notifications/service.py b/src/notifications/service.py index ecd6717..ed64cce 100644 --- a/src/notifications/service.py +++ b/src/notifications/service.py @@ -1,12 +1,55 @@ -from typing import Any -from .data import Notification 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""" + def __init__(self, name: str): + self._name = name + + @property + def name(self): + return self._name + @abc.abstractmethod def notify(self, user: Any, notification: Notification): """Send a notification""" 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