feat: 10/21 회의 반영 — 공유 링크·로그인 없이 댓글·구글 로그인만, 히어로·오늘의 각 좋아요·댓글, 히어로 오늘/내일 스위치, 단풍 지도 65곳·3단계
- 공유: 이미지와 함께 고정 URL을 넘기고 링크도 클립보드에 복사 - 로그인 창은 구글만, 댓글은 로그인 없이 '동네 익명'(링크·전화번호 막기, IP당 하루 20개, 같은 IP만 지우기) - 히어로·오늘의 각 카드에 좋아요·댓글 (PostType HERO·TODAY_GAK) - 히어로 오늘/내일 스위치: 내일 구간별 날씨 점수·기온·최저최고·습도·1위 각, /v1/weather/today?day=tomorrow - 단풍 지도: 단풍 그림 지도, 단풍 전·첫 단풍·절정, 단풍잎·은행잎, 명소 65곳(산림청 예측 + 가까운 지점 날짜) - 하단 탭 바 불투명 (홈 바 자리로 글이 비치지 않게) - 사람 글 동네 우선 정렬·내 글 목록, 내 각 '있는 각에서 불러오기' - 댓글 표 user_id NULL 허용·ip_hash·region_name (운영 DB ALTER 필요)
This commit is contained in:
1 parent
14f24d1ab0
commit
93e041bb91
46 files changed
+1820
-337
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy import delete, func, select, update
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -51,8 +52,9 @@ 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, str, str, str, Optional[str]]]:
|
||||
stmt = select(Comment, User.nickname, User.character, User.color, User.mood).join(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, 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))
|
||||
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())
|
||||
@@ -65,16 +67,20 @@ class ReactionCRUD:
|
||||
stmt = select(CommentLikeAnon.comment_id).where(CommentLikeAnon.ip_hash == ip_hash, CommentLikeAnon.comment_id.in_(comment_ids))
|
||||
return set((await s.scalars(stmt)).all())
|
||||
|
||||
async def add_comment(self, s: AsyncSession, post_id: int, user_id: uuid.UUID, body: str) -> Comment:
|
||||
c = Comment(post_id=post_id, user_id=user_id, body=body)
|
||||
async def add_comment(self, s: AsyncSession, post_id: int, who: Liker, body: str, region_name: Optional[str]) -> Comment:
|
||||
c = Comment(post_id=post_id, user_id=who.user_id, body=body) if who.user_id is not None else Comment(post_id=post_id, ip_hash=who.ip_hash, region_name=region_name, body=body)
|
||||
s.add(c)
|
||||
await s.execute(update(Post).where(Post.post_id == post_id).values(comment_count=Post.comment_count + 1))
|
||||
await s.flush()
|
||||
return c
|
||||
|
||||
async def delete_comment(self, s: AsyncSession, comment_id: int, user_id: uuid.UUID) -> bool:
|
||||
async def anon_comments_since(self, s: AsyncSession, ip_hash: str, since: datetime) -> int:
|
||||
return await s.scalar(select(func.count()).select_from(Comment).where(Comment.user_id.is_(None), Comment.ip_hash == ip_hash, Comment.created_at >= since))
|
||||
|
||||
async def delete_comment(self, s: AsyncSession, comment_id: int, who: Liker) -> bool:
|
||||
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, Comment.user_id == user_id, Comment.deleted.is_(False))
|
||||
update(Comment).where(Comment.comment_id == comment_id, owner, Comment.deleted.is_(False))
|
||||
.values(deleted=True).returning(Comment.post_id)
|
||||
)
|
||||
post_id = res.scalar()
|
||||
|
||||
@@ -2,7 +2,7 @@ import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import delete, func, select, update
|
||||
from sqlalchemy import BigInteger, case, cast, delete, func, select, tuple_, update
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -12,16 +12,29 @@ from crud.reaction_crud import toggle_like_row
|
||||
|
||||
|
||||
class TalkCRUD:
|
||||
async def page(self, s: AsyncSession, viewer: Optional[uuid.UUID], cursor: Optional[int], limit: int) -> list[tuple[Talk, User, Optional[str]]]:
|
||||
"""최신 글부터. 숨김·지운 글과 내가 안 보기로 한 사람의 글은 뺀다."""
|
||||
async def page(
|
||||
self, s: AsyncSession, viewer: Optional[uuid.UUID], sido: Optional[str], boost_sec: int, cursor: Optional[tuple[int, int]], limit: int
|
||||
) -> list[tuple[Talk, User, Optional[str], int]]:
|
||||
"""최신 글부터. 보는 사람과 같은 시도 글은 boost_sec 만큼 늦게 쓴 것처럼 앞에 둔다. 숨김·지운 글과 내가 안 보기로 한 사람의 글은 뺀다.
|
||||
cursor 는 앞 페이지 마지막 글의 (정렬 키, talk_id)."""
|
||||
key = cast(func.floor(func.extract("epoch", Talk.created_at)), BigInteger)
|
||||
if sido:
|
||||
key = key + case((func.left(Talk.region_code, 2) == sido, boost_sec), else_=0)
|
||||
stmt = (
|
||||
select(Talk, User, Region.short_name)
|
||||
select(Talk, User, Region.short_name, key)
|
||||
.join(User, User.user_id == Talk.user_id)
|
||||
.outerjoin(Region, Region.code == Talk.region_code)
|
||||
.where(Talk.deleted.is_(False), Talk.hidden.is_(False), User.deleted.is_(False))
|
||||
)
|
||||
if viewer is not None:
|
||||
stmt = stmt.where(Talk.user_id.not_in(select(UserBlock.blocked_id).where(UserBlock.user_id == viewer)))
|
||||
if cursor is not None:
|
||||
stmt = stmt.where(tuple_(key, Talk.talk_id) < tuple_(*cursor))
|
||||
return list((await s.execute(stmt.order_by(key.desc(), Talk.talk_id.desc()).limit(limit))).all())
|
||||
|
||||
async def mine(self, s: AsyncSession, user_id: uuid.UUID, cursor: Optional[int], limit: int) -> list[tuple[Talk, Optional[str]]]:
|
||||
"""내가 쓴 글, 최신부터. 신고로 숨겨진 글도 쓴 사람에겐 보인다."""
|
||||
stmt = select(Talk, Region.short_name).outerjoin(Region, Region.code == Talk.region_code).where(Talk.user_id == user_id, Talk.deleted.is_(False))
|
||||
if cursor is not None:
|
||||
stmt = stmt.where(Talk.talk_id < cursor)
|
||||
return list((await s.execute(stmt.order_by(Talk.talk_id.desc()).limit(limit))).all())
|
||||
|
||||
Reference in new issue
Block a user