improve-schema
Some checks failed
deploy / deploy (push) Failing after 1m13s

This commit is contained in:
Untone 2023-11-26 14:21:32 +03:00
parent 57e4f9764b
commit 6e6de3818b
2 changed files with 13 additions and 6 deletions

View File

@ -1,12 +1,11 @@
import json
from typing import List, Dict
from orm.notification import Notification
from services.db import local_session
from services.rediscache import redis
def handle_reaction(notification: Dict[str, str | int | List[int]]):
def handle_reaction(notification: dict[str, str | int]):
"""создаеёт новое хранимое уведомление"""
try:
with local_session() as session:

View File

@ -35,6 +35,12 @@ class NotificationSeenResult:
error: str
@strawberry.type
class NotificationsResult:
notifications: List[Notification]
unread: int
def notification_seen_by_viewer(viewer_id, notification_id, session):
seen = (
session.query(NotificationSeen)
@ -49,7 +55,7 @@ def notification_seen_by_viewer(viewer_id, notification_id, session):
class Query:
@strawberry.field
@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"]
@ -72,7 +78,7 @@ class Query:
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
@ -90,7 +96,8 @@ class Mutation:
except Exception as e:
session.rollback()
print(f"[mark_notification_as_read] error: {str(e)}")
return {}
return NotificationSeenResult(error="cant mark as read")
return NotificationSeenResult()
@strawberry.mutation
@login_required
@ -104,7 +111,8 @@ class Mutation:
except Exception as e:
session.rollback()
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)