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:
1 parent
bb1ea12958
commit
b16d4a8f1b
126 files changed
+6921
-62
No files matched your search
@@ -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)
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user