2024-10-21 09:15:44 +00:00
|
|
|
import enum
|
2023-12-17 20:30:20 +00:00
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey, String
|
2023-11-28 10:46:06 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2023-12-17 20:30:20 +00:00
|
|
|
|
2025-06-01 23:56:11 +00:00
|
|
|
from services.db import BaseModel as Base
|
2023-11-28 10:46:06 +00:00
|
|
|
|
|
|
|
|
2024-10-21 09:15:44 +00:00
|
|
|
class InviteStatus(enum.Enum):
|
2024-04-17 15:32:23 +00:00
|
|
|
PENDING = "PENDING"
|
|
|
|
ACCEPTED = "ACCEPTED"
|
|
|
|
REJECTED = "REJECTED"
|
2023-11-28 10:46:06 +00:00
|
|
|
|
2024-10-21 09:15:44 +00:00
|
|
|
@classmethod
|
|
|
|
def from_string(cls, value):
|
|
|
|
return cls(value)
|
|
|
|
|
2023-11-28 10:46:06 +00:00
|
|
|
|
|
|
|
class Invite(Base):
|
2024-04-17 15:32:23 +00:00
|
|
|
__tablename__ = "invite"
|
2023-11-28 10:46:06 +00:00
|
|
|
|
2024-04-17 15:32:23 +00:00
|
|
|
inviter_id = Column(ForeignKey("author.id"), primary_key=True)
|
|
|
|
author_id = Column(ForeignKey("author.id"), primary_key=True)
|
|
|
|
shout_id = Column(ForeignKey("shout.id"), primary_key=True)
|
2023-11-30 08:40:27 +00:00
|
|
|
status = Column(String, default=InviteStatus.PENDING.value)
|
2023-11-28 10:46:06 +00:00
|
|
|
|
2024-10-21 09:15:44 +00:00
|
|
|
inviter = relationship("Author", foreign_keys=[inviter_id])
|
|
|
|
author = relationship("Author", foreign_keys=[author_id])
|
|
|
|
shout = relationship("Shout")
|
|
|
|
|
|
|
|
def set_status(self, status: InviteStatus):
|
2025-06-01 23:56:11 +00:00
|
|
|
self.status = status.value # type: ignore[assignment]
|
2024-10-21 09:15:44 +00:00
|
|
|
|
|
|
|
def get_status(self) -> InviteStatus:
|
|
|
|
return InviteStatus.from_string(self.status)
|