core/orm/notification.py

42 lines
1013 B
Python
Raw Normal View History

2024-03-04 07:35:33 +00:00
import time
from enum import Enum as Enumeration
from sqlalchemy import JSON, Column, ForeignKey, Integer, String
2024-04-19 15:22:07 +00:00
from sqlalchemy.orm import relationship
2024-03-04 07:35:33 +00:00
from orm.author import Author
2024-10-21 07:52:23 +00:00
from services.db import Base
2024-03-04 07:35:33 +00:00
class NotificationEntity(Enumeration):
2024-04-17 15:32:23 +00:00
REACTION = "reaction"
SHOUT = "shout"
FOLLOWER = "follower"
2024-03-04 07:35:33 +00:00
class NotificationAction(Enumeration):
2024-04-17 15:32:23 +00:00
CREATE = "create"
UPDATE = "update"
DELETE = "delete"
SEEN = "seen"
FOLLOW = "follow"
UNFOLLOW = "unfollow"
2024-03-04 07:35:33 +00:00
class NotificationSeen(Base):
2024-04-17 15:32:23 +00:00
__tablename__ = "notification_seen"
2024-03-04 07:35:33 +00:00
2024-04-17 15:32:23 +00:00
viewer = Column(ForeignKey("author.id"))
notification = Column(ForeignKey("notification.id"))
2024-03-04 07:35:33 +00:00
class Notification(Base):
2024-04-17 15:32:23 +00:00
__tablename__ = "notification"
2024-03-04 07:35:33 +00:00
created_at = Column(Integer, server_default=str(int(time.time())))
entity = Column(String, nullable=False)
action = Column(String, nullable=False)
payload = Column(JSON, nullable=True)
2024-04-17 15:32:23 +00:00
seen = relationship(lambda: Author, secondary="notification_seen")