2024-02-16 23:56:15 +00:00
|
|
|
import time
|
2023-12-17 22:20:13 +00:00
|
|
|
from enum import Enum as Enumeration
|
|
|
|
|
2024-02-16 23:56:15 +00:00
|
|
|
from sqlalchemy import JSON, Column, ForeignKey, Integer, String
|
2023-11-26 18:21:14 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2023-12-17 11:42:04 +00:00
|
|
|
|
2023-11-26 18:21:14 +00:00
|
|
|
from orm.author import Author
|
2023-11-23 22:58:55 +00:00
|
|
|
from services.db import Base
|
|
|
|
|
2024-02-04 04:58:44 +00:00
|
|
|
|
2023-11-23 22:58:55 +00:00
|
|
|
class NotificationEntity(Enumeration):
|
2024-02-16 23:56:15 +00:00
|
|
|
REACTION = 'reaction'
|
|
|
|
SHOUT = 'shout'
|
|
|
|
FOLLOWER = 'follower'
|
2023-11-23 22:58:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NotificationAction(Enumeration):
|
2024-02-16 23:56:15 +00:00
|
|
|
CREATE = 'create'
|
|
|
|
UPDATE = 'update'
|
|
|
|
DELETE = 'delete'
|
|
|
|
SEEN = 'seen'
|
|
|
|
FOLLOW = 'follow'
|
|
|
|
UNFOLLOW = 'unfollow'
|
2023-11-23 22:58:55 +00:00
|
|
|
|
|
|
|
|
2023-11-26 18:21:14 +00:00
|
|
|
class NotificationSeen(Base):
|
2024-02-16 23:56:15 +00:00
|
|
|
__tablename__ = 'notification_seen'
|
2023-11-26 18:21:14 +00:00
|
|
|
|
2024-02-16 23:56:15 +00:00
|
|
|
viewer = Column(ForeignKey('author.id'))
|
|
|
|
notification = Column(ForeignKey('notification.id'))
|
2023-11-26 18:21:14 +00:00
|
|
|
|
|
|
|
|
2023-11-23 22:58:55 +00:00
|
|
|
class Notification(Base):
|
2024-02-16 23:56:15 +00:00
|
|
|
__tablename__ = 'notification'
|
2023-11-23 22:58:55 +00:00
|
|
|
|
2024-01-23 08:08:58 +00:00
|
|
|
created_at = Column(Integer, server_default=str(int(time.time())))
|
2024-01-23 09:05:28 +00:00
|
|
|
entity = Column(String, nullable=False)
|
|
|
|
action = Column(String, nullable=False)
|
2024-02-16 23:56:15 +00:00
|
|
|
payload = Column(JSON, nullable=True)
|
2023-11-26 18:21:14 +00:00
|
|
|
|
2024-02-16 23:56:15 +00:00
|
|
|
seen = relationship(lambda: Author, secondary='notification_seen')
|