schema-fix
All checks were successful
deploy / deploy (push) Successful in 1m18s

This commit is contained in:
Untone 2023-11-26 22:00:00 +03:00
parent 0db8a19898
commit f940b7461e
4 changed files with 22 additions and 11 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ __pycache__
.idea .idea
.vscode .vscode
poetry.lock poetry.lock
.venv

View File

@ -24,7 +24,9 @@
3 Запуск локального сервера 3 Запуск локального сервера
```shell ```shell
poetry env use 3.12 mkdir .venv
poetry install python3.12 -m venv .venv
poetry env use .venv/bin/python3.12
poetry update
poetry run strawberry server main poetry run strawberry server main
``` ```

View File

@ -58,6 +58,8 @@ ensure_newline_before_comments = true
line_length = 120 line_length = 120
[tool.pyright] [tool.pyright]
venvPath = "."
venv = ".venv"
include = ["."] include = ["."]
exclude = ["**/__pycache__"] exclude = ["**/__pycache__"]
ignore = [] ignore = []

View File

@ -24,7 +24,7 @@ class Notification:
@strawberry.type @strawberry.type
class NotificationSeenResult: class NotificationSeenResult:
error: str error: str = strawberry.field(default=None, name="error")
@strawberry.type @strawberry.type
@ -40,7 +40,6 @@ class Query:
@login_required @login_required
async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> NotificationsResult: 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"]
nr = NotificationsResult()
with local_session() as session: with local_session() as session:
author = session.query(Author).filter(Author.user == user_id).first() author = session.query(Author).filter(Author.user == user_id).first()
NotificationSeenAlias = aliased(NotificationSeen) NotificationSeenAlias = aliased(NotificationSeen)
@ -53,7 +52,7 @@ class Query:
NotificationSeen, NotificationSeen,
and_(NotificationSeen.viewer == author.id, NotificationSeen.notification == NotificationMessage.id), and_(NotificationSeen.viewer == author.id, NotificationSeen.notification == NotificationMessage.id),
).limit(limit).offset(offset).all() ).limit(limit).offset(offset).all()
nr.notifications = [] notifications = []
for n in nnn: for n in nnn:
ntf = Notification() ntf = Notification()
ntf.id = n.id ntf.id = n.id
@ -62,10 +61,18 @@ class Query:
ntf.action = n.action ntf.action = n.action
ntf.created_at = n.created_at ntf.created_at = n.created_at
ntf.seen = n.seen ntf.seen = n.seen
nr.notifications.append(ntf) notifications.append(ntf)
nr.unread = sum(1 for n in nr.notifications if author.id in n.seen) nr = NotificationsResult(
nr.total = session.query(NotificationMessage).count() notifications = notifications,
unread = sum(1 for n in notifications if author.id in n.seen),
total = session.query(NotificationMessage).count()
)
return nr return nr
return NotificationsResult(
notifications=[],
total = 0,
unread = 0
)
@strawberry.type @strawberry.type
@ -83,8 +90,7 @@ 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)}")
nsr = NotificationSeenResult() nsr = NotificationSeenResult(error = "cant mark as read")
nsr.error = "cant mark as read"
return nsr return nsr
return NotificationSeenResult() return NotificationSeenResult()