feat: P2V 파이프라인 연동 및 좋아요·댓글·공유 지원

- 무빙 포스터(p2v_video)·롱컷(p2v_playreel) 파이프라인과 워커, 갤러리·내 콘텐츠 노출
- 좋아요·댓글: comment/video_reaction에 p2v_playreel_id 추가, 종류별 CHECK 확장
- P2V 소프트 삭제(is_deleted), queued/running 삭제 차단
- 공개 상세·공유 OG 페이지 추가
- 삭제된 부모 댓글이 목록에서 사라지던 has_live_reply 서브쿼리 버그 수정
- 마이그레이션: migration_2026-10-15_p2v_reactions.sql
This commit is contained in:
skkim committed 2026-10-15 10:42:30 +09:00
1 parent bb1ea12958
commit b16d4a8f1b
126 files changed
+6921 -62

No files matched your search

+16 -7
View File
@@ -9,8 +9,6 @@ Comment API Router
- DELETE /comment/{comment_id}: 본인 댓글 소프트 삭제 (로그인 필수)
"""
from typing import Literal
from fastapi import APIRouter, Depends, Query
from sqlalchemy.ext.asyncio import AsyncSession
@@ -20,7 +18,12 @@ from app.comment.schemas.comment_schema import (
CommentItem,
DeleteCommentResponse,
)
from app.comment.services.comment import create_comment, delete_comment, list_comments
from app.comment.services.comment import (
ContentType,
create_comment,
delete_comment,
list_comments,
)
from app.database.session import get_session
from app.dependencies.pagination import PaginationParams, get_pagination_params
from app.user.dependencies.auth import get_current_user, get_current_user_optional
@@ -62,9 +65,12 @@ router = APIRouter(prefix="/comment", tags=["Comment"])
async def post_comment(
video_id: int,
body: CommentCreateRequest,
type: Literal["video", "ssul"] = Query(
type: ContentType = Query(
default="video",
description="콘텐츠 종류. video.id 와 ssul_content.id 가 겹치므로 반드시 함께 보낼 것",
description=(
"콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스, p2v_video: 무빙 포스터, "
"p2v_playreel: 롱컷). id 가 종류별로 겹치므로 반드시 함께 보낼 것"
),
),
current_user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
@@ -120,9 +126,12 @@ async def post_comment(
)
async def get_comments(
video_id: int,
type: Literal["video", "ssul"] = Query(
type: ContentType = Query(
default="video",
description="콘텐츠 종류. video.id 와 ssul_content.id 가 겹치므로 반드시 함께 보낼 것",
description=(
"콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스, p2v_video: 무빙 포스터, "
"p2v_playreel: 롱컷). id 가 종류별로 겹치므로 반드시 함께 보낼 것"
),
),
current_user: User | None = Depends(get_current_user_optional),
session: AsyncSession = Depends(get_session),
+22 -5
View File
@@ -31,9 +31,11 @@ class Comment(Base):
작성자 닉네임은 카카오 로그인 정보를 작성 시점에 그대로 저장한 스냅샷이며,
프로필 이미지는 별도 컬럼 없이 응답 시 User 테이블을 조인해 최신값을 조회한다.
**ADO2 영상과 썰박스 콘텐츠를 모두 담는다.** 대상은 `video_id` 또는 `content_id`
중 **정확히 하나**만 채워지며, 이를 DB `CHECK` 로 강제한다. MySQL 은 하나의 FK 가
두 테이블을 조건부로 가리키게 할 수 없어 컬럼을 나눠 둔 것이다.
**ADO2 영상·썰박스·P2V(무빙 포스터·롱컷)를 모두 담는다.** 대상은 `video_id`,
`content_id`, `p2v_video_id`, `p2v_playreel_id` 중 **정확히 하나**만 채워지며, 이를
DB `CHECK` 로 강제한다. MySQL 은 하나의 FK 가 여러 테이블을 조건부로 가리키게 할 수
없어 컬럼을 나눠 둔 것이다. (DB 에는 옛 `p2v_poster_id` 도 남아 있어 CHECK 에 포함돼
있으나, 대응 테이블이 모델에 없어 여기서는 매핑하지 않는다.)
별도의 종류 컬럼은 두지 않는다 — 어느 FK 가 채워졌는지가 곧 종류이고,
컬럼을 하나 더 두면 둘이 어긋날 수 있다.
"""
@@ -41,11 +43,14 @@ class Comment(Base):
__tablename__ = "comment"
__table_args__ = (
CheckConstraint(
"(video_id IS NULL) <> (content_id IS NULL)",
"(video_id IS NOT NULL) + (content_id IS NOT NULL) "
"+ (p2v_video_id IS NOT NULL) + (p2v_playreel_id IS NOT NULL) = 1",
name="ck_comment_one_target",
),
Index("idx_comment_video_id", "video_id"),
Index("idx_comment_content_id", "content_id"),
Index("idx_comment_p2v_video_id", "p2v_video_id"),
Index("idx_comment_p2v_playreel_id", "p2v_playreel_id"),
Index("idx_comment_user_uuid", "user_uuid"),
Index("idx_comment_parent_id", "parent_id"),
Index("idx_comment_is_deleted", "is_deleted"),
@@ -59,7 +64,7 @@ class Comment(Base):
id: Mapped[int] = mapped_column(
Integer, primary_key=True, autoincrement=True, comment="고유 식별자"
)
# 대상은 아래 둘 중 **정확히 하나**만 채워진다 (ck_comment_one_target).
# 대상은 아래 넷 중 **정확히 하나**만 채워진다 (ck_comment_one_target).
video_id: Mapped[Optional[int]] = mapped_column(
Integer,
ForeignKey("video.id", ondelete="CASCADE"),
@@ -73,6 +78,18 @@ class Comment(Base):
nullable=True,
comment="썰박스 콘텐츠 id (ADO2 댓글이면 NULL)",
)
p2v_video_id: Mapped[Optional[int]] = mapped_column(
BigInteger,
ForeignKey("p2v_video.id", ondelete="CASCADE"),
nullable=True,
comment="무빙 포스터 id (다른 종류 댓글이면 NULL)",
)
p2v_playreel_id: Mapped[Optional[int]] = mapped_column(
BigInteger,
ForeignKey("p2v_playreel.id", ondelete="CASCADE"),
nullable=True,
comment="롱컷 id (다른 종류 댓글이면 NULL)",
)
user_uuid: Mapped[str] = mapped_column(
ForeignKey("user.user_uuid", ondelete="CASCADE"),
nullable=False,
+28 -14
View File
@@ -4,24 +4,34 @@ from typing import List, Literal, Optional
from fastapi import HTTPException
from sqlalchemy import exists, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import aliased
from app.comment.models import Comment
from app.comment.schemas.comment_schema import CommentItem, ReplyItem
from app.p2v.services.public_content import P2V_TYPES, public_exists_query
from app.ssulbox.models import SsulContent
from app.user.models import User
from app.utils.pagination import PaginatedResponse
from app.video.models import Video
ContentType = Literal["video", "ssul"]
ContentType = Literal["video", "ssul", "p2v_video", "p2v_playreel"]
#: 종류 → 댓글이 대상을 가리키는 컬럼 이름
_TARGET_ATTR = {
"video": "video_id",
"ssul": "content_id",
"p2v_video": "p2v_video_id",
"p2v_playreel": "p2v_playreel_id",
}
def _target_col(content_type: ContentType):
"""댓글이 달린 대상을 가리키는 컬럼.
`comment` 는 ADO2 영상과 썰박스를 함께 담고 `video_id` / `content_id` 중
정확히 하나만 채운다(CHECK 로 강제). 종류는 어느 컬럼이 채워졌는지가 결정한다.
`comment` 는 ADO2 영상·썰박스·P2V 를 함께 담고 종류별 컬럼 중 정확히 하나만
채운다(CHECK 로 강제). 종류는 어느 컬럼이 채워졌는지가 결정한다.
"""
return Comment.video_id if content_type == "video" else Comment.content_id
return getattr(Comment, _TARGET_ATTR[content_type])
async def _ensure_target_exists(
@@ -29,11 +39,13 @@ async def _ensure_target_exists(
content_type: ContentType,
target_id: int,
) -> None:
"""댓글 대상(영상 또는 썰박스 콘텐츠)이 존재·공개 상태인지 확인.
"""댓글 대상(영상·썰박스·P2V 콘텐츠)이 존재·공개 상태인지 확인.
id 가 종류별 독립 시퀀스라, 반대쪽 테이블에 같은 id 가 있어도 잡으면 안 된다.
id 가 종류별 독립 시퀀스라, 다른 테이블에 같은 id 가 있어도 잡으면 안 된다.
"""
if content_type == "ssul":
if content_type in P2V_TYPES:
q = public_exists_query(content_type, target_id)
elif content_type == "ssul":
q = select(SsulContent.id).where(
SsulContent.id == target_id,
SsulContent.status == "done",
@@ -67,8 +79,8 @@ async def _validate_parent(
if parent is None:
raise HTTPException(status_code=400, detail="부모 댓글을 찾을 수 없습니다.")
# 부모가 같은 종류의 같은 대상에 달렸는지 본다. video_id 만 비교하면
# 썰박스 댓글(video_id=NULL)에 ADO2 대댓글이 달리는 교차를 못 막는다.
parent_target = parent.video_id if content_type == "video" else parent.content_id
# 다른 종류 댓글(video_id=NULL)에 대댓글이 달리는 교차를 못 막는다.
parent_target = getattr(parent, _TARGET_ATTR[content_type])
if parent_target != target_id:
raise HTTPException(status_code=400, detail="다른 콘텐츠의 댓글에는 대댓글을 달 수 없습니다.")
if parent.parent_id is not None:
@@ -128,9 +140,8 @@ async def create_comment(
await _validate_parent(session, parent_id, content_type, video_id)
comment = Comment(
# 종류에 따라 둘 중 하나만 채운다 (CHECK ck_comment_one_target 이 강제)
video_id=video_id if content_type == "video" else None,
content_id=video_id if content_type == "ssul" else None,
# 종류에 맞는 컬럼 하나만 채운다 (CHECK ck_comment_one_target 이 강제)
**{_TARGET_ATTR[content_type]: video_id},
user_uuid=user_uuid,
nickname=nickname,
parent_id=parent_id,
@@ -153,11 +164,14 @@ async def list_comments(
offset = (page - 1) * page_size
# 살아있는 자식이 있는지 확인하는 서브쿼리
# 자식은 같은 테이블이라 별칭이 필요하다. 별칭 없이 Comment 끼리 비교하면
# 바깥 행을 자기 자신과 비교해 항상 거짓이 된다.
reply = aliased(Comment)
has_live_reply = (
exists()
.where(
Comment.parent_id == Comment.id,
Comment.is_deleted == False, # noqa: E712
reply.parent_id == Comment.id,
reply.is_deleted == False, # noqa: E712
)
.correlate(Comment)
)