2022-09-12 10:19:35 +00:00
|
|
|
import time
|
2024-02-15 13:17:23 +00:00
|
|
|
from typing import Optional, TYPE_CHECKING
|
2022-02-14 19:02:05 +00:00
|
|
|
|
2024-02-15 21:50:18 +00:00
|
|
|
from sqlalchemy.orm import Mapped, relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.sql.sqltypes import *
|
2022-02-14 19:02:05 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.classes import Base
|
2024-02-15 21:50:18 +00:00
|
|
|
from files.helpers.types import comment_id_fk_pk, post_id_fk_pk, user_id_fk_pk
|
2022-11-15 09:19:08 +00:00
|
|
|
|
2024-02-15 13:17:23 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from files.classes.comment import Comment
|
|
|
|
from files.classes.post import Post
|
|
|
|
|
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
class SaveRelationship(Base):
|
2023-08-23 21:57:39 +00:00
|
|
|
__tablename__ = "save_relationship"
|
2022-02-14 19:02:05 +00:00
|
|
|
|
2024-02-15 21:50:18 +00:00
|
|
|
user_id: Mapped[user_id_fk_pk]
|
|
|
|
post_id: Mapped[post_id_fk_pk]
|
2024-02-15 13:17:23 +00:00
|
|
|
created_utc: Mapped[Optional[int]]
|
2022-02-14 19:02:05 +00:00
|
|
|
|
2024-02-15 13:17:23 +00:00
|
|
|
post: Mapped["Post"] = relationship(uselist=False)
|
2022-07-16 18:51:48 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2023-06-07 23:26:32 +00:00
|
|
|
return f"<{self.__class__.__name__}(user_id={self.user_id}, post_id={self.post_id})>"
|
2022-02-14 19:02:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CommentSaveRelationship(Base):
|
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
__tablename__ = "comment_save_relationship"
|
2022-02-14 19:02:05 +00:00
|
|
|
|
2024-02-15 21:50:18 +00:00
|
|
|
user_id: Mapped[user_id_fk_pk]
|
|
|
|
comment_id: Mapped[comment_id_fk_pk]
|
2024-02-15 13:17:23 +00:00
|
|
|
created_utc: Mapped[Optional[int]]
|
2022-07-02 06:48:04 +00:00
|
|
|
|
2024-02-15 13:17:23 +00:00
|
|
|
comment: Mapped["Comment"] = relationship(uselist=False)
|
2022-07-16 18:51:48 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(user_id={self.user_id}, comment_id={self.comment_id})>"
|