Files
notifier/orm/notification.py

42 lines
1013 B
Python
Raw Normal View History

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