This commit is contained in:
parent
57e4f9764b
commit
6e6de3818b
|
@ -1,12 +1,11 @@
|
||||||
import json
|
import json
|
||||||
from typing import List, Dict
|
|
||||||
|
|
||||||
from orm.notification import Notification
|
from orm.notification import Notification
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
|
|
||||||
|
|
||||||
def handle_reaction(notification: Dict[str, str | int | List[int]]):
|
def handle_reaction(notification: dict[str, str | int]):
|
||||||
"""создаеёт новое хранимое уведомление"""
|
"""создаеёт новое хранимое уведомление"""
|
||||||
try:
|
try:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
|
|
|
@ -35,6 +35,12 @@ class NotificationSeenResult:
|
||||||
error: str
|
error: str
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.type
|
||||||
|
class NotificationsResult:
|
||||||
|
notifications: List[Notification]
|
||||||
|
unread: int
|
||||||
|
|
||||||
|
|
||||||
def notification_seen_by_viewer(viewer_id, notification_id, session):
|
def notification_seen_by_viewer(viewer_id, notification_id, session):
|
||||||
seen = (
|
seen = (
|
||||||
session.query(NotificationSeen)
|
session.query(NotificationSeen)
|
||||||
|
@ -49,7 +55,7 @@ def notification_seen_by_viewer(viewer_id, notification_id, session):
|
||||||
class Query:
|
class Query:
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
@login_required
|
@login_required
|
||||||
async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> dict[str, List[Notification] | int]:
|
async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> NotificationsResult:
|
||||||
"""загружаем уведомления"""
|
"""загружаем уведомления"""
|
||||||
user_id = info.context["user_id"]
|
user_id = info.context["user_id"]
|
||||||
|
|
||||||
|
@ -72,7 +78,7 @@ class Query:
|
||||||
|
|
||||||
unread = sum(1 for n in nslist if not n.seen_by_viewer)
|
unread = sum(1 for n in nslist if not n.seen_by_viewer)
|
||||||
|
|
||||||
return {"notifications": nslist, "unread": unread}
|
return NotificationsResult(notifications=nslist, unread=unread)
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
|
@ -90,7 +96,8 @@ class Mutation:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
print(f"[mark_notification_as_read] error: {str(e)}")
|
print(f"[mark_notification_as_read] error: {str(e)}")
|
||||||
return {}
|
return NotificationSeenResult(error="cant mark as read")
|
||||||
|
return NotificationSeenResult()
|
||||||
|
|
||||||
@strawberry.mutation
|
@strawberry.mutation
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -104,7 +111,8 @@ class Mutation:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
print(f"[mark_all_notifications_as_read] error: {str(e)}")
|
print(f"[mark_all_notifications_as_read] error: {str(e)}")
|
||||||
return {}
|
return NotificationSeenResult(error="cant mark as read")
|
||||||
|
return NotificationSeenResult()
|
||||||
|
|
||||||
|
|
||||||
schema = strawberry.Schema(query=Query, mutation=Mutation)
|
schema = strawberry.Schema(query=Query, mutation=Mutation)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user