콘텐츠 공유 페이지 및 공유하기, 좋아요, 댓글 기능 추가

This commit is contained in:
skkim committed 2026-05-27 13:08:25 +09:00
1 parent 346b461e9c
commit 5f3e8ec341
27 files changed
+1546 -95

No files matched your search

+67 -2
View File
@@ -1,15 +1,17 @@
from datetime import datetime
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, List, Optional
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, String, func
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, String, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database.session import Base
if TYPE_CHECKING:
from app.comment.models import Comment
from app.home.models import Project
from app.lyric.models import Lyric
from app.song.models import Song
from app.user.models import User
class Video(Base):
@@ -33,6 +35,8 @@ class Video(Base):
project: 연결된 Project
lyric: 연결된 Lyric
song: 연결된 Song
comments: 영상 댓글 목록
likes: 영상 좋아요 목록
"""
__tablename__ = "video"
@@ -132,6 +136,20 @@ class Video(Base):
back_populates="videos",
)
comments: Mapped[List["Comment"]] = relationship(
"Comment",
back_populates="video",
cascade="all, delete-orphan",
lazy="noload",
)
reactions: Mapped[List["VideoReaction"]] = relationship(
"VideoReaction",
back_populates="video",
cascade="all, delete-orphan",
lazy="noload",
)
def __repr__(self) -> str:
def truncate(value: str | None, max_len: int = 10) -> str:
if value is None:
@@ -145,3 +163,50 @@ class Video(Base):
f"status='{self.status}'"
f")>"
)
class VideoReaction(Base):
"""
영상 반응 테이블
사용자가 영상에 반응(현재는 좋아요)을 남기면 생성, 다시 누르면 삭제(토글).
(user_uuid, video_id) 유니크 제약으로 1인 1회 보장.
향후 reaction_type 컬럼 추가로 다양한 반응 종류 확장 가능.
"""
__tablename__ = "video_reaction"
__table_args__ = (
UniqueConstraint("user_uuid", "video_id", name="uq_video_reaction_user_video"),
Index("idx_video_reaction_video_id", "video_id"),
Index("idx_video_reaction_user_uuid", "user_uuid"),
{
"mysql_engine": "InnoDB",
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
},
)
id: Mapped[int] = mapped_column(
Integer, primary_key=True, autoincrement=True, comment="고유 식별자"
)
video_id: Mapped[int] = mapped_column(
Integer,
ForeignKey("video.id", ondelete="CASCADE"),
nullable=False,
comment="연결된 Video의 id",
)
user_uuid: Mapped[str] = mapped_column(
String(36),
ForeignKey("user.user_uuid", ondelete="CASCADE"),
nullable=False,
comment="반응한 사용자 UUID",
)
created_at: Mapped[datetime] = mapped_column(
DateTime,
nullable=False,
server_default=func.now(),
comment="반응 일시",
)
video: Mapped["Video"] = relationship("Video", back_populates="reactions")
user: Mapped["User"] = relationship("User", back_populates="video_reactions")