diff --git a/src/main.py b/src/main.py index d046769..3249a8b 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from src.notifications.service import make_notification_service +from src.services.notifications import NotificationService, get_notification_service from src.services.email import get_service as get_email_service from src.services.users import get_service as get_user_service from src.infra.db import get_database diff --git a/src/notifications/__init__.py b/src/notifications/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/notifications/data.py b/src/notifications/data.py deleted file mode 100644 index a2633c8..0000000 --- a/src/notifications/data.py +++ /dev/null @@ -1,38 +0,0 @@ -from dataclasses import dataclass, field - -URL = str - - -@dataclass -class NotificationAction: - # A unique identifier for the action - action: str - # The title to show with the action - title: str - # Where to navigate to when clicked. - navigate: URL | None = None - - -@dataclass -class Notification: - """ - Details to show in a notification - - Much of the data here is intended to match the arguments to the [showNotification](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification) - Web API, but this content is ideally displayable in other contexts (for example in Email or RSS) - """ - - # The main title content to show - title: str - # The content of the notification - content: str - - # The UNIX timestamp in milliseconds since the epoch associated with this notification - timestamp: int - # A list of actions included with this notification - actions: list[NotificationAction] = field(default_factory=list) - # The location of an icon to show as the icon for this notification - icon: URL | None = None - - # The location of an image associated with this notification - image: URL | None = None diff --git a/src/notifications/service.py b/src/services/notifications.py similarity index 50% rename from src/notifications/service.py rename to src/services/notifications.py index ed64cce..67e8b12 100644 --- a/src/notifications/service.py +++ b/src/services/notifications.py @@ -2,11 +2,45 @@ import abc from typing import Any from src.services.email import EmailService -from src.config import Config -from .data import Notification +from dataclasses import dataclass, field -# MUSTFIX: Needs real users! +URL = str + + +@dataclass +class NotificationAction: + # A unique identifier for the action + action: str + # The title to show with the action + title: str + # Where to navigate to when clicked. + navigate: URL | None = None + + +@dataclass +class Notification: + """ + Details to show in a notification + + Much of the data here is intended to match the arguments to the [showNotification](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification) + Web API, but this content is ideally displayable in other contexts (for example in Email or RSS) + """ + + # The main title content to show + title: str + # The content of the notification + content: str + + # The UNIX timestamp in milliseconds since the epoch associated with this notification + timestamp: int + # A list of actions included with this notification + actions: list[NotificationAction] = field(default_factory=list) + # The location of an icon to show as the icon for this notification + icon: URL | None = None + + # The location of an image associated with this notification + image: URL | None = None class NotificationSender(abc.ABC): @@ -48,7 +82,7 @@ class EmailNotifier(NotificationSender): pass -def make_notification_service(email_service: EmailService): +def get_notification_service(email_service: EmailService): service = NotificationService() service.register_sender(EmailNotifier(email_service))