From 4630299a5643d79371bc7d5acfb189fe92c6ded2 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 24 Nov 2023 05:45:38 +0300 Subject: [PATCH] schema-fix --- README.md | 17 ++++++++++++++++- notifier.graphql | 37 +++++++++++++++++++++++++++++++++++++ resolvers/notifications.py | 15 +++++++-------- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b678172..a84385d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ### Что делает - слушает redis PubSub каналы реакций и постов - - собирает уведомления + - сохраняет уведомления - формирует дайджесты @@ -11,3 +11,18 @@ - не отправляет сообщения по SSE - не определяет кому их отправлять + + +## Как разрабатывать локально + +Установить +- Redis +- Postgres + +Затем + +```shell +poetry install +poetry env use 3.12 +poetry run python server.py +``` diff --git a/notifier.graphql b/notifier.graphql index e69de29..91c713d 100644 --- a/notifier.graphql +++ b/notifier.graphql @@ -0,0 +1,37 @@ + +enum NotificationAction { + CREATE, + UPDATE, + DELETE, + SEEN +} +enum NotificationEntity { + SHOUT, + REACTION +} + + +type Notification { + id: Int! + action: NotificationAction! + entity: NotificationEntity! + created_at: Int! + seen: Boolean! + data: String # JSON + occurrences: Int +} + +input NotificationsQueryParams { + limit: Int + offset: Int +} + +type NotificationsQueryResult { + notifications: [Notification]! + total: Int! + unread: Int! +} + +type Query { + loadNotifications(params: NotificationsQueryParams!): NotificationsQueryResult! +} diff --git a/resolvers/notifications.py b/resolvers/notifications.py index f8d7b82..73bca5b 100644 --- a/resolvers/notifications.py +++ b/resolvers/notifications.py @@ -5,6 +5,10 @@ from services.db import local_session from services.schema import mutation, query from orm.notification import Notification +# TODO: occurrencies? + +# TODO: use of Author.id? + @query.field("loadNotifications") @login_required @@ -16,12 +20,7 @@ async def load_notifications(_, info, params=None): limit = params.get("limit", 50) offset = params.get("offset", 0) - q = ( - select(Notification) - .order_by(desc(Notification.created_at)) - .limit(limit) - .offset(offset) - ) + q = select(Notification).order_by(desc(Notification.created_at)).limit(limit).offset(offset) notifications = [] with local_session() as session: @@ -39,8 +38,8 @@ async def load_notifications(_, info, params=None): return { "notifications": notifications, - "totalCount": total_count, - "totalUnreadCount": total_unread_count, + "total": total_count, + "unread": total_unread_count, }