Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
feat: add endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TatarinAlba committed Nov 23, 2024
1 parent dd3bf14 commit e6c8997
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/src/modules/notifies/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def get_notification_by_user_id(self, user_id: PydanticObjectId) -> list[N
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)
return await Notification.find(Notification.sent is False).to_list()


notification_repository = NotificationRepository()
8 changes: 8 additions & 0 deletions backend/src/modules/notifies/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def create_notification(notification_create: NotificationCreateReq, auth:
event_title=event.title,
target_date=notification_create["notification_options"]["expiration_time"],
user_id=user_id,
event_id=event.id,
endpoint=notification_create["notification_options"]["endpoint"],
keys=notification_create["notification_options"]["keys"],
)
Expand All @@ -42,6 +43,7 @@ async def create_notification(notification_create: NotificationCreateReq, auth:
sport_title=sport.sport,
target_date=notification_create["notification_options"]["expiration_time"],
user_id=user_id,
sport_id=sport.id,
endpoint=notification_create["notification_options"]["endpoint"],
keys=notification_create["notification_options"]["keys"],
)
Expand All @@ -55,3 +57,9 @@ async def get_notification(notification_id: PydanticObjectId):
if not notification:
raise HTTPException(status_code=404, detail="Notification not found")
return notification


@router.post("/my-subscriptions")
async def get_user_subscriptions(auth: USER_AUTH) -> list[Notification]:
user_id = auth.user_id
return await notification_repository.get_notification_by_user_id(user_id)
8 changes: 7 additions & 1 deletion backend/src/storages/mongo/notifies.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import datetime

from beanie import PydanticObjectId
from pymongo import IndexModel

from src.pydantic_base import BaseSchema
from src.storages.mongo.__base__ import CustomDocument


class NotifySchema(BaseSchema):
event_title: str | None = None
event_id: PydanticObjectId | None = None
sport_title: str | None = None
sport_id: PydanticObjectId | None = None
endpoint: str
keys: dict
target_date: datetime.datetime
Expand All @@ -17,4 +20,7 @@ class NotifySchema(BaseSchema):


class Notification(NotifySchema, CustomDocument):
pass
class Settings:
indexes = [
IndexModel(["user_id", "event_id", "sport_id"], unique=True),
]

0 comments on commit e6c8997

Please sign in to comment.