diff --git a/.gitignore b/.gitignore index fde4dab..dac81c4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__ .idea .vscode poetry.lock +.venv diff --git a/README.md b/README.md index 290ffae..4e77da5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ 3 Запуск локального сервера ```shell -poetry env use 3.12 -poetry install +mkdir .venv +python3.12 -m venv .venv +poetry env use .venv/bin/python3.12 +poetry update poetry run strawberry server main ``` diff --git a/pyproject.toml b/pyproject.toml index ea11fdd..b91509a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,8 @@ ensure_newline_before_comments = true line_length = 120 [tool.pyright] +venvPath = "." +venv = ".venv" include = ["."] exclude = ["**/__pycache__"] ignore = [] diff --git a/resolvers/schema.py b/resolvers/schema.py index a234b52..211b3f8 100644 --- a/resolvers/schema.py +++ b/resolvers/schema.py @@ -24,7 +24,7 @@ class Notification: @strawberry.type class NotificationSeenResult: - error: str + error: str = strawberry.field(default=None, name="error") @strawberry.type @@ -40,7 +40,6 @@ class Query: @login_required async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> NotificationsResult: user_id = info.context["user_id"] - nr = NotificationsResult() with local_session() as session: author = session.query(Author).filter(Author.user == user_id).first() NotificationSeenAlias = aliased(NotificationSeen) @@ -53,7 +52,7 @@ class Query: NotificationSeen, and_(NotificationSeen.viewer == author.id, NotificationSeen.notification == NotificationMessage.id), ).limit(limit).offset(offset).all() - nr.notifications = [] + notifications = [] for n in nnn: ntf = Notification() ntf.id = n.id @@ -62,10 +61,18 @@ class Query: ntf.action = n.action ntf.created_at = n.created_at ntf.seen = n.seen - nr.notifications.append(ntf) - nr.unread = sum(1 for n in nr.notifications if author.id in n.seen) - nr.total = session.query(NotificationMessage).count() - return nr + notifications.append(ntf) + nr = NotificationsResult( + notifications = notifications, + unread = sum(1 for n in notifications if author.id in n.seen), + total = session.query(NotificationMessage).count() + ) + return nr + return NotificationsResult( + notifications=[], + total = 0, + unread = 0 + ) @strawberry.type @@ -83,8 +90,7 @@ class Mutation: except Exception as e: session.rollback() print(f"[mark_notification_as_read] error: {str(e)}") - nsr = NotificationSeenResult() - nsr.error = "cant mark as read" + nsr = NotificationSeenResult(error = "cant mark as read") return nsr return NotificationSeenResult()