From 5f9d413a57df32bf834483250091e3a67d21de9d Mon Sep 17 00:00:00 2001 From: Amirhossein Khalili Date: Sat, 25 Apr 2026 12:00:05 +0330 Subject: [PATCH] refactor(notifications): align app structure with backend conventions --- apps/notifications/api/__init__.py | 1 + apps/notifications/{ => api}/serializers.py | 0 apps/notifications/{ => api}/urls.py | 2 +- apps/notifications/{ => api}/views.py | 2 +- apps/notifications/services/__init__.py | 23 +++++++++++++++++++ .../{ => services}/membership_events.py | 2 +- .../{services.py => services/store.py} | 0 .../tests/test_membership_events.py | 2 +- apps/notifications/tests/test_services.py | 2 +- apps/notifications/tests/test_views.py | 3 ++- apps/projects/api/views.py | 2 +- apps/workspaces/api/serializers.py | 2 +- apps/workspaces/api/views.py | 2 +- config/urls.py | 2 +- 14 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 apps/notifications/api/__init__.py rename apps/notifications/{ => api}/serializers.py (100%) rename apps/notifications/{ => api}/urls.py (95%) rename apps/notifications/{ => api}/views.py (99%) create mode 100644 apps/notifications/services/__init__.py rename apps/notifications/{ => services}/membership_events.py (99%) rename apps/notifications/{services.py => services/store.py} (100%) diff --git a/apps/notifications/api/__init__.py b/apps/notifications/api/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/apps/notifications/api/__init__.py @@ -0,0 +1 @@ + diff --git a/apps/notifications/serializers.py b/apps/notifications/api/serializers.py similarity index 100% rename from apps/notifications/serializers.py rename to apps/notifications/api/serializers.py diff --git a/apps/notifications/urls.py b/apps/notifications/api/urls.py similarity index 95% rename from apps/notifications/urls.py rename to apps/notifications/api/urls.py index 83d84fc..3bb11fa 100644 --- a/apps/notifications/urls.py +++ b/apps/notifications/api/urls.py @@ -1,7 +1,7 @@ from django.urls import include, path from rest_framework.routers import DefaultRouter -from apps.notifications import views +from apps.notifications.api import views router = DefaultRouter() router.register("box", views.NotificationListViewSet, basename="box") diff --git a/apps/notifications/views.py b/apps/notifications/api/views.py similarity index 99% rename from apps/notifications/views.py rename to apps/notifications/api/views.py index e7b80d2..9594c51 100644 --- a/apps/notifications/views.py +++ b/apps/notifications/api/views.py @@ -13,7 +13,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from apps.notifications.serializers import ( +from apps.notifications.api.serializers import ( NotificationDeleteResponseSerializer, NotificationListResponseSerializer, NotificationMarkAllReadResponseSerializer, diff --git a/apps/notifications/services/__init__.py b/apps/notifications/services/__init__.py new file mode 100644 index 0000000..61f7750 --- /dev/null +++ b/apps/notifications/services/__init__.py @@ -0,0 +1,23 @@ +from apps.notifications.services.membership_events import ( + notify_project_membership_added, + notify_project_membership_deactivated, + notify_project_membership_removed, + notify_project_membership_role_changed, + notify_workspace_membership_added, + notify_workspace_membership_deactivated, + notify_workspace_membership_removed, + notify_workspace_membership_role_changed, +) +from apps.notifications.services.store import RedisNotificationStore + +__all__ = [ + "RedisNotificationStore", + "notify_workspace_membership_added", + "notify_workspace_membership_role_changed", + "notify_workspace_membership_deactivated", + "notify_workspace_membership_removed", + "notify_project_membership_added", + "notify_project_membership_role_changed", + "notify_project_membership_deactivated", + "notify_project_membership_removed", +] diff --git a/apps/notifications/membership_events.py b/apps/notifications/services/membership_events.py similarity index 99% rename from apps/notifications/membership_events.py rename to apps/notifications/services/membership_events.py index a237a07..a689762 100644 --- a/apps/notifications/membership_events.py +++ b/apps/notifications/services/membership_events.py @@ -1,4 +1,4 @@ -from apps.notifications.services import RedisNotificationStore +from apps.notifications.services.store import RedisNotificationStore def _actor_name(actor) -> str: diff --git a/apps/notifications/services.py b/apps/notifications/services/store.py similarity index 100% rename from apps/notifications/services.py rename to apps/notifications/services/store.py diff --git a/apps/notifications/tests/test_membership_events.py b/apps/notifications/tests/test_membership_events.py index dacbd60..56af8b2 100644 --- a/apps/notifications/tests/test_membership_events.py +++ b/apps/notifications/tests/test_membership_events.py @@ -1,7 +1,7 @@ import pytest from rest_framework.test import APIClient -from apps.notifications import services +from apps.notifications.services import store as services from apps.notifications.services import RedisNotificationStore from apps.notifications.tests.test_services import FakeRedis from apps.projects.models import Project, ProjectMembership diff --git a/apps/notifications/tests/test_services.py b/apps/notifications/tests/test_services.py index deae25a..647f733 100644 --- a/apps/notifications/tests/test_services.py +++ b/apps/notifications/tests/test_services.py @@ -3,7 +3,7 @@ from collections import defaultdict import pytest -from apps.notifications import services +from apps.notifications.services import store as services from apps.notifications.services import RedisNotificationStore diff --git a/apps/notifications/tests/test_views.py b/apps/notifications/tests/test_views.py index 8826c3b..35dc08e 100644 --- a/apps/notifications/tests/test_views.py +++ b/apps/notifications/tests/test_views.py @@ -6,7 +6,8 @@ import pytest from django.utils import timezone from rest_framework.test import APIClient -from apps.notifications import services, views +from apps.notifications.api import views +from apps.notifications.services import store as services from apps.notifications.services import RedisNotificationStore from apps.notifications.tests.test_services import FakePubSub, FakeRedis from apps.users.models import User diff --git a/apps/projects/api/views.py b/apps/projects/api/views.py index 5b7558b..57b4cd0 100644 --- a/apps/projects/api/views.py +++ b/apps/projects/api/views.py @@ -11,7 +11,7 @@ from django_filters.rest_framework import DjangoFilterBackend from core.paginations.limit_offset import CustomLimitOffsetPagination -from apps.notifications.membership_events import ( +from apps.notifications.services import ( notify_project_membership_added, notify_project_membership_deactivated, notify_project_membership_removed, diff --git a/apps/workspaces/api/serializers.py b/apps/workspaces/api/serializers.py index 82635b6..96b2b77 100644 --- a/apps/workspaces/api/serializers.py +++ b/apps/workspaces/api/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from apps.notifications.membership_events import notify_workspace_membership_added +from apps.notifications.services import notify_workspace_membership_added from apps.users.models import User from core.serializers.base import BaseModelSerializer from apps.workspaces.models import Workspace, WorkspaceMembership diff --git a/apps/workspaces/api/views.py b/apps/workspaces/api/views.py index 451a469..dcf4e99 100644 --- a/apps/workspaces/api/views.py +++ b/apps/workspaces/api/views.py @@ -7,7 +7,7 @@ from django_filters.rest_framework import DjangoFilterBackend from rest_framework.viewsets import ModelViewSet from rest_framework.permissions import IsAuthenticated -from apps.notifications.membership_events import ( +from apps.notifications.services import ( notify_workspace_membership_added, notify_workspace_membership_deactivated, notify_workspace_membership_removed, diff --git a/config/urls.py b/config/urls.py index bd0fbd8..be25ddd 100644 --- a/config/urls.py +++ b/config/urls.py @@ -21,7 +21,7 @@ urlpatterns = [ path('api/', include('apps.projects.api.urls'), name="projects"), path('api/', include('apps.tags.api.urls'), name="tags"), path('api/', include('apps.time_entries.api.urls'), name="time_entries"), - path("api/notifications/", include("apps.notifications.urls"), name="notifications"), + path("api/notifications/", include("apps.notifications.api.urls"), name="notifications"), ] if settings.DEBUG: