This commit is contained in:
parent
0db8a19898
commit
f940b7461e
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ __pycache__
|
|||
.idea
|
||||
.vscode
|
||||
poetry.lock
|
||||
.venv
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -58,6 +58,8 @@ ensure_newline_before_comments = true
|
|||
line_length = 120
|
||||
|
||||
[tool.pyright]
|
||||
venvPath = "."
|
||||
venv = ".venv"
|
||||
include = ["."]
|
||||
exclude = ["**/__pycache__"]
|
||||
ignore = []
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user