Skip to content

Commit

Permalink
Adds a way to get all unread in app notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Nov 9, 2024
1 parent f9cd314 commit dc82dbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions vintasend/services/notification_backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def get_notification(
) -> "Notification":
raise NotImplementedError

@abstractmethod
def filter_all_in_app_unread_notifications(
self, user_id: int | str | uuid.UUID
) -> Iterable["Notification"]:
raise NotImplementedError

@abstractmethod
def filter_in_app_unread_notifications(
self, user_id: int | str | uuid.UUID, page: int, page_size: int
Expand Down
11 changes: 7 additions & 4 deletions vintasend/services/notification_backends/stubs/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def get_notification(
except StopIteration as e:
raise NotificationNotFoundError("Notification not found") from e

def filter_in_app_unread_notifications(
self, user_id: int | str | uuid.UUID, page: int, page_size: int
def filter_all_in_app_unread_notifications(
self, user_id: int | str | uuid.UUID
) -> list[Notification]:
notifications = [
n
Expand All @@ -194,9 +194,12 @@ def filter_in_app_unread_notifications(
and n.status == NotificationStatus.SENT.value
and n.notification_type == NotificationTypes.IN_APP.value
]
return notifications

# page is 1-indexed
return self.__paginate_notifications(notifications, page, page_size)
def filter_in_app_unread_notifications(
self, user_id: int | str | uuid.UUID, page: int, page_size: int
) -> list[Notification]:
return self.__paginate_notifications(self.filter_all_in_app_unread_notifications(user_id), page, page_size)

def __paginate_notifications(self, notifications: list[Notification], page: int, page_size: int):
# page is 1-indexed
Expand Down

0 comments on commit dc82dbe

Please sign in to comment.