This repository has been archived by the owner on Dec 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e8fae7
commit 3c3530f
Showing
4 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
from beanie import PydanticObjectId | ||
|
||
from src.modules.notifies.scheams import NotificationCreate | ||
from src.storages.mongo.notifies import Notification | ||
|
||
|
||
class NotificationRepository: | ||
async def create_notification(self, notification_data: NotificationCreate) -> PydanticObjectId: | ||
notification = Notification(**notification_data.model_dump()) | ||
await notification.insert() | ||
return notification.id | ||
async def create_notification(self, notification_data: Notification) -> PydanticObjectId: | ||
await notification_data.insert() | ||
return notification_data.id | ||
|
||
async def get_notification(self, notification_id: PydanticObjectId) -> Notification: | ||
return await Notification.get(notification_id) | ||
|
||
async def get_notification_by_user_id(self, user_id: PydanticObjectId) -> list[Notification]: | ||
return await Notification.find(Notification.user_id == user_id).to_list() | ||
|
||
async def list_all_valid_notifications(self) -> list[Notification]: | ||
return await Notification.find(Notification.sent is False) | ||
|
||
|
||
notification_repository = NotificationRepository() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
from datetime import datetime | ||
from typing import Literal | ||
|
||
from pydantic import BaseModel | ||
from beanie import PydanticObjectId | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class NotificationCreate(BaseModel): | ||
event_title: str | ||
notification_options: dict | ||
target_date: datetime | ||
user_id: int | ||
sent: bool = False | ||
class NotificationOption(BaseModel): | ||
class Keys(BaseModel): | ||
p256dh: str | ||
auth: str | ||
|
||
endpoint: str | ||
expiration_time: datetime | ||
keys: Keys | ||
|
||
class NotificationResponse(BaseModel): | ||
id: int | ||
event_title: str | ||
notification_options: dict | ||
target_date: datetime | ||
user_id: int | ||
sent: bool = False | ||
|
||
class EventNotification(BaseModel): | ||
type: Literal["event"] | ||
id: PydanticObjectId | ||
|
||
|
||
class SportNotification(BaseModel): | ||
type: Literal["sport"] | ||
id: PydanticObjectId | ||
|
||
|
||
class NotificationCreateReq(BaseModel): | ||
notification_type: EventNotification | SportNotification = Field(discriminator="type") | ||
notification_options: NotificationOption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters