notifier/orm/notification.py

43 lines
1.0 KiB
Python
Raw Normal View History

2023-12-17 22:20:13 +00:00
from enum import Enum as Enumeration
2024-02-04 04:58:44 +00:00
from sqlalchemy import JSON as JSONType
from sqlalchemy import 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-01-23 08:08:58 +00:00
import time
2023-11-23 22:58:55 +00:00
2024-02-04 04:58:44 +00:00
2023-11-23 22:58:55 +00:00
class NotificationEntity(Enumeration):
2024-01-23 09:05:28 +00:00
REACTION = "reaction"
SHOUT = "shout"
FOLLOWER = "follower"
2023-11-23 22:58:55 +00:00
class NotificationAction(Enumeration):
2024-01-23 09:05:28 +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):
__tablename__ = "notification_seen"
viewer = Column(ForeignKey("author.id"))
notification = Column(ForeignKey("notification.id"))
2023-11-23 22:58:55 +00:00
class Notification(Base):
__tablename__ = "notification"
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)
2023-11-26 18:21:14 +00:00
payload = Column(JSONType, nullable=True)
seen = relationship(lambda: Author, secondary="notification_seen")