chore: main 병합 — 단풍·띠 좋아요, 밀림 수정, 글 주제·사진 Blob, 애드센스
This commit is contained in:
commit
e30f41de68
31 files changed
+831
-88
No files matched your search
@@ -13,7 +13,8 @@ from crud.reaction_crud import toggle_like_row
|
||||
|
||||
class TalkCRUD:
|
||||
async def page(
|
||||
self, s: AsyncSession, viewer: Optional[uuid.UUID], sido: Optional[str], boost_sec: int, cursor: Optional[tuple[int, int]], limit: int
|
||||
self, s: AsyncSession, viewer: Optional[uuid.UUID], sido: Optional[str], boost_sec: int, cursor: Optional[tuple[int, int]], limit: int,
|
||||
topic: Optional[int] = None,
|
||||
) -> list[tuple[Talk, User, Optional[str], int]]:
|
||||
"""최신 글부터. 보는 사람과 같은 시도 글은 boost_sec 만큼 늦게 쓴 것처럼 앞에 둔다. 숨김·지운 글과 내가 안 보기로 한 사람의 글은 뺀다.
|
||||
cursor 는 앞 페이지 마지막 글의 (정렬 키, talk_id)."""
|
||||
@@ -28,10 +29,24 @@ class TalkCRUD:
|
||||
)
|
||||
if viewer is not None:
|
||||
stmt = stmt.where(Talk.user_id.not_in(select(UserBlock.blocked_id).where(UserBlock.user_id == viewer)))
|
||||
if topic is not None:
|
||||
stmt = stmt.where(Talk.topic == topic)
|
||||
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 recent(self, s: AsyncSession, viewer: Optional[uuid.UUID], since: datetime, limit: int) -> list[tuple[Talk, User, Optional[str]]]:
|
||||
"""since 뒤에 쓴 글 최신순 (숨김·지운 글, 내가 안 보기로 한 사람 글 빼고). 피드 묶음을 고를 재료"""
|
||||
stmt = (
|
||||
select(Talk, User, Region.short_name)
|
||||
.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), Talk.created_at >= since)
|
||||
)
|
||||
if viewer is not None:
|
||||
stmt = stmt.where(Talk.user_id.not_in(select(UserBlock.blocked_id).where(UserBlock.user_id == viewer)))
|
||||
return list((await s.execute(stmt.order_by(Talk.created_at.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))
|
||||
@@ -48,8 +63,10 @@ class TalkCRUD:
|
||||
async def count_since(self, s: AsyncSession, user_id: uuid.UUID, since: datetime) -> int:
|
||||
return await s.scalar(select(func.count()).select_from(Talk).where(Talk.user_id == user_id, Talk.created_at >= since))
|
||||
|
||||
async def add(self, s: AsyncSession, user_id: uuid.UUID, region_code: str, body: str, weather: Optional[str], image: Optional[str] = None) -> Talk:
|
||||
t = Talk(user_id=user_id, region_code=region_code, body=body, weather=weather, image=image)
|
||||
async def add(
|
||||
self, s: AsyncSession, user_id: uuid.UUID, region_code: str, body: str, weather: Optional[str], image: Optional[str] = None, topic: int = 1
|
||||
) -> Talk:
|
||||
t = Talk(user_id=user_id, region_code=region_code, body=body, weather=weather, image=image, topic=topic)
|
||||
s.add(t)
|
||||
await s.flush()
|
||||
await s.refresh(t)
|
||||
|
||||
Reference in new issue
Block a user