Merge branch 'react-native' into release/1026-merge

# Conflicts:
#	backend/common/enums.py
#	backend/router/v1/auth/account.py
#	frontend/.dockerignore
#	frontend/package-lock.json
#	frontend/package.json
#	frontend/public/terms.html
#	frontend/src/api/client/index.ts
#	frontend/src/b/BLayout.tsx
#	frontend/src/b/Sheets.tsx
#	shared/api/client/@tanstack/react-query.gen.ts
#	shared/api/client/sdk.gen.ts
#	shared/api/client/types.gen.ts
This commit is contained in:
minaChoi committed 2026-10-26 15:36:05 +09:00
commit 5d18fa51fa
148 files changed
+21940 -4532

No files matched your search

+62 -10
View File
@@ -2,13 +2,15 @@ import uuid
from datetime import datetime
from typing import Optional
from sqlalchemy import delete, func, select, update
from sqlalchemy import delete, func, or_, select, update
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.ext.asyncio import AsyncSession
from common.database.model.models import Comment, CommentLike, CommentLikeAnon, Post, PostLike, PostLikeAnon, PostSave, User
from common.database.model.models import Comment, CommentLike, CommentLikeAnon, CommentReport, Post, PostLike, PostLikeAnon, PostSave, User, UserBlock
from common.liker import Liker
HIDE_AT = 3 # 신고가 이만큼 쌓이면 모두에게서 숨긴다
async def toggle_like_row(s: AsyncSession, who: Liker, member: type, anon: type, id_name: str, id_value: int, on: bool) -> bool:
"""로그인했으면 member 표에 user_id 로, 아니면 anon 표에 ip_hash 로 넣거나 지운다. 실제로 바뀌었으면 True."""
@@ -52,9 +54,16 @@ class ReactionCRUD:
stmt = stmt.where(Post.post_id < cursor)
return list((await s.execute(stmt.order_by(Post.post_id.desc()).limit(limit))).all())
async def comments(self, s: AsyncSession, post_id: int, cursor: Optional[int], limit: int) -> list[tuple[Comment, Optional[str], Optional[str], Optional[str], Optional[str]]]:
"""로그인 없이 쓴 댓글은 User 칸이 모두 None 이다."""
stmt = select(Comment, User.nickname, User.character, User.color, User.mood).outerjoin(User, User.user_id == Comment.user_id).where(Comment.post_id == post_id, Comment.deleted.is_(False))
async def comments(self, s: AsyncSession, post_id: int, viewer: Optional[uuid.UUID], cursor: Optional[int], limit: int) -> list[tuple[Comment, Optional[str], Optional[str], Optional[str], Optional[str]]]:
"""로그인 없이 쓴 댓글은 User 칸이 모두 None 이다. 숨긴 댓글은 빼고, 보는 사람이 신고한 댓글·차단한 사람의 댓글도 뺀다."""
stmt = select(Comment, User.nickname, User.character, User.color, User.mood).outerjoin(User, User.user_id == Comment.user_id).where(
Comment.post_id == post_id, Comment.deleted.is_(False), Comment.is_hidden.is_(False)
)
if viewer is not None:
stmt = stmt.where(
Comment.comment_id.not_in(select(CommentReport.comment_id).where(CommentReport.user_id == viewer)),
or_(Comment.user_id.is_(None), Comment.user_id.not_in(select(UserBlock.blocked_id).where(UserBlock.user_id == viewer))),
)
if cursor is not None:
stmt = stmt.where(Comment.comment_id > cursor)
return list((await s.execute(stmt.order_by(Comment.comment_id).limit(limit))).all())
@@ -81,18 +90,61 @@ class ReactionCRUD:
owner = Comment.user_id == who.user_id if who.user_id is not None else (Comment.user_id.is_(None) & (Comment.ip_hash == who.ip_hash))
res = await s.execute(
update(Comment).where(Comment.comment_id == comment_id, owner, Comment.deleted.is_(False))
.values(deleted=True).returning(Comment.post_id)
.values(deleted=True).returning(Comment.post_id, Comment.is_hidden)
)
post_id = res.scalar()
if post_id is None:
row = res.first()
if row is None:
return False
await s.execute(update(Post).where(Post.post_id == post_id).values(comment_count=Post.comment_count - 1))
# 숨긴 댓글은 이미 댓글 수에서 빠져 있다
if not row.is_hidden:
await s.execute(update(Post).where(Post.post_id == row.post_id).values(comment_count=Post.comment_count - 1))
return True
async def toggle_comment_like(self, s: AsyncSession, comment_id: int, who: Liker, on: bool) -> Optional[int]:
exists = await s.scalar(select(Comment.comment_id).where(Comment.comment_id == comment_id, Comment.deleted.is_(False)))
exists = await s.scalar(select(Comment.comment_id).where(Comment.comment_id == comment_id, Comment.deleted.is_(False), Comment.is_hidden.is_(False)))
if exists is None:
return None
if await toggle_like_row(s, who, CommentLike, CommentLikeAnon, "comment_id", comment_id, on):
await s.execute(update(Comment).where(Comment.comment_id == comment_id).values(like_count=Comment.like_count + (1 if on else -1)))
return await s.scalar(select(Comment.like_count).where(Comment.comment_id == comment_id))
async def comment_author(self, s: AsyncSession, comment_id: int):
"""지금 보이는 댓글이면 (comment_id, user_id) 행, 없으면 None. 로그인 없이 쓴 댓글은 user_id 가 None."""
return (await s.execute(select(Comment.comment_id, Comment.user_id).where(Comment.comment_id == comment_id, Comment.deleted.is_(False), Comment.is_hidden.is_(False)))).first()
async def report_comment(self, s: AsyncSession, comment_id: int, user_id: uuid.UUID, reason: int) -> None:
"""같은 사람이 두 번 신고해도 한 번만 센다. HIDE_AT 건이 되면 숨기고 댓글 수에서 뺀다."""
res = await s.execute(insert(CommentReport).values(comment_id=comment_id, user_id=user_id, reason=reason).on_conflict_do_nothing().returning(CommentReport.comment_id))
if res.first() is None:
return
await s.execute(update(Comment).where(Comment.comment_id == comment_id).values(report_count=Comment.report_count + 1))
res = await s.execute(
update(Comment).where(Comment.comment_id == comment_id, Comment.report_count >= HIDE_AT, Comment.is_hidden.is_(False), Comment.deleted.is_(False))
.values(is_hidden=True).returning(Comment.post_id)
)
post_id = res.scalar()
if post_id is not None:
await s.execute(update(Post).where(Post.post_id == post_id).values(comment_count=Post.comment_count - 1))
async def set_hidden(self, s: AsyncSession, comment_id: int, hidden: bool) -> bool:
"""운영자가 댓글을 숨기거나 되살린다. 실제로 바뀌었을 때만 댓글 수를 고친다."""
res = await s.execute(
update(Comment).where(Comment.comment_id == comment_id, Comment.is_hidden.is_(not hidden), Comment.deleted.is_(False))
.values(is_hidden=hidden).returning(Comment.post_id)
)
post_id = res.scalar()
if post_id is None:
return False
await s.execute(update(Post).where(Post.post_id == post_id).values(comment_count=Post.comment_count + (-1 if hidden else 1)))
return True
async def block(self, s: AsyncSession, user_id: uuid.UUID, blocked_id: uuid.UUID) -> None:
await s.execute(insert(UserBlock).values(user_id=user_id, blocked_id=blocked_id).on_conflict_do_nothing())
async def unblock(self, s: AsyncSession, user_id: uuid.UUID, blocked_id: uuid.UUID) -> bool:
res = await s.execute(delete(UserBlock).where(UserBlock.user_id == user_id, UserBlock.blocked_id == blocked_id).returning(UserBlock.blocked_id))
return res.first() is not None
async def blocked(self, s: AsyncSession, user_id: uuid.UUID) -> list[User]:
stmt = select(User).join(UserBlock, UserBlock.blocked_id == User.user_id).where(UserBlock.user_id == user_id).order_by(UserBlock.created_at.desc())
return list((await s.scalars(stmt)).all())
+29 -2
View File
@@ -1,11 +1,12 @@
import uuid
from collections import Counter
from datetime import datetime, timezone
from typing import Optional
from sqlalchemy import select
from sqlalchemy import delete, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from common.database.model.models import User
from common.database.model.models import Comment, CommentLike, CommentReport, Post, PostLike, PostSave, User, UserBlock
class UserCRUD:
@@ -46,3 +47,29 @@ class UserCRUD:
user.updated_at = datetime.now(timezone.utc)
await s.flush()
return user
async def agree_terms(self, s: AsyncSession, user_id: uuid.UUID) -> None:
await s.execute(update(User).where(User.user_id == user_id, User.terms_agreed_at.is_(None)).values(terms_agreed_at=datetime.now(timezone.utc)))
async def withdraw(self, s: AsyncSession, user_id: uuid.UUID) -> None:
"""계정과 그 사람이 남긴 좋아요·저장·댓글·신고·차단을 모두 지우고, 게시물·댓글에 쌓인 수를 그만큼 줄인다."""
liked_posts = (await s.scalars(delete(PostLike).where(PostLike.user_id == user_id).returning(PostLike.post_id))).all()
if liked_posts:
await s.execute(update(Post).where(Post.post_id.in_(liked_posts)).values(like_count=Post.like_count - 1))
liked_comments = (await s.scalars(delete(CommentLike).where(CommentLike.user_id == user_id).returning(CommentLike.comment_id))).all()
if liked_comments:
await s.execute(update(Comment).where(Comment.comment_id.in_(liked_comments)).values(like_count=Comment.like_count - 1))
await s.execute(delete(PostSave).where(PostSave.user_id == user_id))
reported = (await s.scalars(delete(CommentReport).where(CommentReport.user_id == user_id).returning(CommentReport.comment_id))).all()
if reported:
await s.execute(update(Comment).where(Comment.comment_id.in_(reported)).values(report_count=Comment.report_count - 1))
await s.execute(delete(UserBlock).where((UserBlock.user_id == user_id) | (UserBlock.blocked_id == user_id)))
mine = (await s.execute(delete(Comment).where(Comment.user_id == user_id).returning(Comment.comment_id, Comment.post_id, Comment.deleted, Comment.is_hidden))).all()
if mine:
ids = [c for c, _, _, _ in mine]
await s.execute(delete(CommentLike).where(CommentLike.comment_id.in_(ids)))
await s.execute(delete(CommentReport).where(CommentReport.comment_id.in_(ids)))
# 이미 지웠거나 숨긴 댓글은 댓글 수에서 빠져 있다
for post_id, n in Counter(p for _, p, deleted, hidden in mine if not deleted and not hidden).items():
await s.execute(update(Post).where(Post.post_id == post_id).values(comment_count=Post.comment_count - n))
await s.execute(delete(User).where(User.user_id == user_id))