Coverage for polar/notification_recipient/repository.py: 37%
24 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
1from collections.abc import Sequence 1a
2from uuid import UUID 1a
4from polar.kit.repository import ( 1a
5 RepositoryBase,
6 RepositorySoftDeletionIDMixin,
7 RepositorySoftDeletionMixin,
8)
9from polar.kit.repository.base import Options 1a
10from polar.models.notification_recipient import NotificationRecipient 1a
12from .schemas import NotificationRecipientPlatform 1a
15class NotificationRecipientRepository( 1a
16 RepositorySoftDeletionIDMixin[NotificationRecipient, UUID],
17 RepositorySoftDeletionMixin[NotificationRecipient],
18 RepositoryBase[NotificationRecipient],
19):
20 model = NotificationRecipient 1a
22 async def delete( 1a
23 self, notification_recipient_id: UUID, user_id: UUID, *, flush: bool = False
24 ) -> None:
25 # First get the notification recipient
26 statement = (
27 self.get_base_statement()
28 .where(NotificationRecipient.id == notification_recipient_id)
29 .where(NotificationRecipient.user_id == user_id)
30 )
31 notification_recipient = await self.get_one_or_none(statement)
33 # If notification recipient exists, soft delete it
34 if notification_recipient:
35 await self.soft_delete(notification_recipient, flush=flush)
37 return None
39 async def list_by_user( 1a
40 self,
41 user_id: UUID,
42 platform: NotificationRecipientPlatform | None,
43 expo_push_token: str | None,
44 *,
45 options: Options = (),
46 ) -> Sequence[NotificationRecipient]:
47 statement = self.get_base_statement().where(
48 NotificationRecipient.user_id == user_id
49 )
51 if expo_push_token:
52 statement = statement.where(
53 NotificationRecipient.expo_push_token == expo_push_token
54 )
56 if platform:
57 statement = statement.where(NotificationRecipient.platform == platform)
59 return await self.get_all(statement.options(*options))
61 async def get_by_expo_token( 1a
62 self, expo_push_token: str
63 ) -> NotificationRecipient | None:
64 statement = self.get_base_statement().where(
65 NotificationRecipient.expo_push_token == expo_push_token
66 )
67 return await self.get_one_or_none(statement)