This commit is contained in:
parent
62f2876ade
commit
c6f160c8cf
1
main.py
1
main.py
|
@ -51,6 +51,7 @@ def create_all_tables():
|
||||||
author.AuthorFollower,
|
author.AuthorFollower,
|
||||||
shout.Shout,
|
shout.Shout,
|
||||||
shout.ShoutAuthor,
|
shout.ShoutAuthor,
|
||||||
|
author.AuthorBookmark,
|
||||||
topic.Topic,
|
topic.Topic,
|
||||||
topic.TopicFollower,
|
topic.TopicFollower,
|
||||||
shout.ShoutTopic,
|
shout.ShoutTopic,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from enum import Enum as Enumeration
|
import enum
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, String
|
from sqlalchemy import Column, ForeignKey, String
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
@ -6,11 +6,15 @@ from sqlalchemy.orm import relationship
|
||||||
from services.db import Base
|
from services.db import Base
|
||||||
|
|
||||||
|
|
||||||
class InviteStatus(Enumeration):
|
class InviteStatus(enum.Enum):
|
||||||
PENDING = "PENDING"
|
PENDING = "PENDING"
|
||||||
ACCEPTED = "ACCEPTED"
|
ACCEPTED = "ACCEPTED"
|
||||||
REJECTED = "REJECTED"
|
REJECTED = "REJECTED"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_string(cls, value):
|
||||||
|
return cls(value)
|
||||||
|
|
||||||
|
|
||||||
class Invite(Base):
|
class Invite(Base):
|
||||||
__tablename__ = "invite"
|
__tablename__ = "invite"
|
||||||
|
@ -20,6 +24,12 @@ class Invite(Base):
|
||||||
shout_id = Column(ForeignKey("shout.id"), primary_key=True)
|
shout_id = Column(ForeignKey("shout.id"), primary_key=True)
|
||||||
status = Column(String, default=InviteStatus.PENDING.value)
|
status = Column(String, default=InviteStatus.PENDING.value)
|
||||||
|
|
||||||
inviter = relationship("author", foreign_keys=[inviter_id])
|
inviter = relationship("Author", foreign_keys=[inviter_id])
|
||||||
author = relationship("author", foreign_keys=[author_id])
|
author = relationship("Author", foreign_keys=[author_id])
|
||||||
shout = relationship("shout")
|
shout = relationship("Shout")
|
||||||
|
|
||||||
|
def set_status(self, status: InviteStatus):
|
||||||
|
self.status = status.value
|
||||||
|
|
||||||
|
def get_status(self) -> InviteStatus:
|
||||||
|
return InviteStatus.from_string(self.status)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import enum
|
||||||
import time
|
import time
|
||||||
from enum import Enum as Enumeration
|
|
||||||
|
|
||||||
from sqlalchemy import JSON, Column, ForeignKey, Integer, String
|
from sqlalchemy import JSON, Column, ForeignKey, Integer, String
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
@ -8,13 +8,18 @@ from orm.author import Author
|
||||||
from services.db import Base
|
from services.db import Base
|
||||||
|
|
||||||
|
|
||||||
class NotificationEntity(Enumeration):
|
class NotificationEntity(enum.Enum):
|
||||||
REACTION = "reaction"
|
REACTION = "reaction"
|
||||||
SHOUT = "shout"
|
SHOUT = "shout"
|
||||||
FOLLOWER = "follower"
|
FOLLOWER = "follower"
|
||||||
|
COMMUNITY = "community"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_string(cls, value):
|
||||||
|
return cls(value)
|
||||||
|
|
||||||
|
|
||||||
class NotificationAction(Enumeration):
|
class NotificationAction(enum.Enum):
|
||||||
CREATE = "create"
|
CREATE = "create"
|
||||||
UPDATE = "update"
|
UPDATE = "update"
|
||||||
DELETE = "delete"
|
DELETE = "delete"
|
||||||
|
@ -22,20 +27,37 @@ class NotificationAction(Enumeration):
|
||||||
FOLLOW = "follow"
|
FOLLOW = "follow"
|
||||||
UNFOLLOW = "unfollow"
|
UNFOLLOW = "unfollow"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_string(cls, value):
|
||||||
|
return cls(value)
|
||||||
|
|
||||||
|
|
||||||
class NotificationSeen(Base):
|
class NotificationSeen(Base):
|
||||||
__tablename__ = "notification_seen"
|
__tablename__ = "notification_seen"
|
||||||
|
|
||||||
viewer = Column(ForeignKey("author.id"))
|
viewer = Column(ForeignKey("author.id"), primary_key=True)
|
||||||
notification = Column(ForeignKey("notification.id"))
|
notification = Column(ForeignKey("notification.id"), primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class Notification(Base):
|
class Notification(Base):
|
||||||
__tablename__ = "notification"
|
__tablename__ = "notification"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
created_at = Column(Integer, server_default=str(int(time.time())))
|
created_at = Column(Integer, server_default=str(int(time.time())))
|
||||||
entity = Column(String, nullable=False)
|
entity = Column(String, nullable=False)
|
||||||
action = Column(String, nullable=False)
|
action = Column(String, nullable=False)
|
||||||
payload = Column(JSON, nullable=True)
|
payload = Column(JSON, nullable=True)
|
||||||
|
|
||||||
seen = relationship(lambda: Author, secondary="notification_seen")
|
seen = relationship(Author, secondary="notification_seen")
|
||||||
|
|
||||||
|
def set_entity(self, entity: NotificationEntity):
|
||||||
|
self.entity = entity.value
|
||||||
|
|
||||||
|
def get_entity(self) -> NotificationEntity:
|
||||||
|
return NotificationEntity.from_string(self.entity)
|
||||||
|
|
||||||
|
def set_action(self, action: NotificationAction):
|
||||||
|
self.action = action.value
|
||||||
|
|
||||||
|
def get_action(self) -> NotificationAction:
|
||||||
|
return NotificationAction.from_string(self.action)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
from sqlalchemy import ARRAY, Boolean, Column, ForeignKey, Integer, String
|
||||||
|
|
||||||
from services.db import Base
|
from services.db import Base
|
||||||
|
|
||||||
|
@ -24,3 +24,5 @@ class Topic(Base):
|
||||||
pic = Column(String, nullable=True, comment="Picture")
|
pic = Column(String, nullable=True, comment="Picture")
|
||||||
community = Column(ForeignKey("community.id"), default=1)
|
community = Column(ForeignKey("community.id"), default=1)
|
||||||
oid = Column(String, nullable=True, comment="Old ID")
|
oid = Column(String, nullable=True, comment="Old ID")
|
||||||
|
|
||||||
|
parent_ids = Column(ARRAY(Integer), nullable=True, comment="Parent Topic IDs")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user