notification-model-fix
This commit is contained in:
parent
140e46e9f2
commit
ac424cf803
|
@ -1,7 +1,7 @@
|
|||
from enum import Enum as Enumeration
|
||||
|
||||
from sqlalchemy import JSON as JSONType, func, cast
|
||||
from sqlalchemy import Column, Enum, ForeignKey, Integer
|
||||
from sqlalchemy import Column, Enum, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.orm.session import engine
|
||||
|
||||
|
@ -10,18 +10,18 @@ from services.db import Base
|
|||
import time
|
||||
|
||||
class NotificationEntity(Enumeration):
|
||||
REACTION = 1
|
||||
SHOUT = 2
|
||||
FOLLOWER = 3
|
||||
REACTION = "reaction"
|
||||
SHOUT = "shout"
|
||||
FOLLOWER = "follower"
|
||||
|
||||
|
||||
class NotificationAction(Enumeration):
|
||||
CREATE = 1
|
||||
UPDATE = 2
|
||||
DELETE = 3
|
||||
SEEN = 4
|
||||
FOLLOW = 5
|
||||
UNFOLLOW = 6
|
||||
CREATE = "create"
|
||||
UPDATE = "update"
|
||||
DELETE = "delete"
|
||||
SEEN = "seen"
|
||||
FOLLOW = "follow"
|
||||
UNFOLLOW = "unfollow"
|
||||
|
||||
|
||||
class NotificationSeen(Base):
|
||||
|
@ -35,8 +35,8 @@ class Notification(Base):
|
|||
__tablename__ = "notification"
|
||||
|
||||
created_at = Column(Integer, server_default=str(int(time.time())))
|
||||
entity = Column(Enum(NotificationEntity), nullable=False)
|
||||
action = Column(Enum(NotificationAction), nullable=False)
|
||||
entity = Column(String, nullable=False)
|
||||
action = Column(String, nullable=False)
|
||||
payload = Column(JSONType, nullable=True)
|
||||
|
||||
seen = relationship(lambda: Author, secondary="notification_seen")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from orm.notification import Notification
|
||||
from orm.notification import Notification, NotificationAction, NotificationEntity
|
||||
from resolvers.model import NotificationReaction, NotificationAuthor, NotificationShout
|
||||
from services.db import local_session
|
||||
from services.rediscache import redis
|
||||
|
|
|
@ -6,7 +6,7 @@ from resolvers.model import (
|
|||
NotificationAuthor,
|
||||
NotificationsResult,
|
||||
)
|
||||
from orm.notification import NotificationSeen, Notification
|
||||
from orm.notification import NotificationAction, NotificationEntity, NotificationSeen, Notification
|
||||
from typing import Dict, List
|
||||
import time, json
|
||||
import strawberry
|
||||
|
@ -59,8 +59,8 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
|||
notifications_by_thread: Dict[str, List[Notification]] = {}
|
||||
groups_by_thread: Dict[str, NotificationGroup] = {}
|
||||
with local_session() as session:
|
||||
total = session.query(Notification).filter(and_(Notification.action == "create", Notification.created_at > after)).count()
|
||||
unread = session.query(Notification).filter(and_(Notification.action == "create", Notification.created_at > after, Notification.seen.is_not(True))).count()
|
||||
total = session.query(Notification).filter(and_(Notification.action == NotificationAction.CREATE.value, Notification.created_at > after)).count()
|
||||
unread = session.query(Notification).filter(and_(Notification.action == NotificationAction.CREATE.value, Notification.created_at > after, Notification.seen.is_not(True))).count()
|
||||
notifications_result = session.execute(query)
|
||||
for n, seen in notifications_result:
|
||||
thread_id = ""
|
||||
|
@ -87,7 +87,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
|||
notifications.append(n)
|
||||
notifications_by_thread[thread_id] = notifications
|
||||
groups_amount += 1
|
||||
elif n.entity == "reaction" and n.action == "create":
|
||||
elif n.entity == NotificationEntity.REACTION.value and n.action == NotificationAction.CREATE.value:
|
||||
reaction: NotificationReaction = payload
|
||||
shout: NotificationShout = reaction.shout
|
||||
thread_id += f"{reaction.shout}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user