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