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
@@ -20,6 +20,8 @@ DAILY_MAX = 5
|
||||
# 로그인한 서로 다른 사람의 신고가 이만큼 쌓이면 운영자 확인 전까지 숨긴다
|
||||
HIDE_AT = 3
|
||||
PAGE = 20
|
||||
# 보는 사람과 같은 시도에서 쓴 글은 이만큼 늦게 쓴 글처럼 앞에 둔다
|
||||
LOCAL_BOOST = timedelta(hours=12)
|
||||
|
||||
# 링크(http, www, 도메인 꼴)와 전화번호(010-1234-5678, 01012345678, 02-123-4567)
|
||||
_LINK = re.compile(r"https?://|www\.|[a-z0-9-]+\.(?:com|net|kr|co|org|io|me|ly|gl)\b", re.I)
|
||||
@@ -38,6 +40,22 @@ def weather_line(row: Optional[WeatherHourly]) -> Optional[str]:
|
||||
return f"{round(float(row.temp_c))}° {word}".strip()
|
||||
|
||||
|
||||
def spread_authors(views: list["TalkView"]) -> list["TalkView"]:
|
||||
"""같은 사람 글이 붙으면 뒤에서 다른 사람 글을 당겨 끼운다."""
|
||||
out = list(views)
|
||||
for i in range(1, len(out)):
|
||||
if out[i].author.user_id == out[i - 1].author.user_id:
|
||||
j = next((k for k in range(i + 1, len(out)) if out[k].author.user_id != out[i - 1].author.user_id), None)
|
||||
if j is not None:
|
||||
out.insert(i, out.pop(j))
|
||||
return out
|
||||
|
||||
|
||||
def parse_cursor(cursor: str) -> Optional[tuple[int, int]]:
|
||||
key, _, talk_id = cursor.partition("_")
|
||||
return (int(key), int(talk_id)) if key.lstrip("-").isdigit() and talk_id.isdigit() else None
|
||||
|
||||
|
||||
@dataclass
|
||||
class TalkView:
|
||||
talk: Talk
|
||||
@@ -51,21 +69,39 @@ class TalkService:
|
||||
def __init__(self, crud: TalkCRUD = Depends(TalkCRUD), regions: RegionCRUD = Depends(RegionCRUD), weather: WeatherCRUD = Depends(WeatherCRUD)) -> None:
|
||||
self.crud, self.regions, self.weather = crud, regions, weather
|
||||
|
||||
async def page(self, user: Optional[User], ip_hash: str, cursor: Optional[int]) -> tuple[ErrorType, list[TalkView]]:
|
||||
async def page(self, user: Optional[User], ip_hash: str, region_code: Optional[str], cursor: Optional[str]) -> tuple[ErrorType, list[TalkView], Optional[str]]:
|
||||
"""한 페이지와 다음 페이지 cursor. 같은 사람 글은 페이지 안에서 떨어뜨린다."""
|
||||
after = parse_cursor(cursor) if cursor else None
|
||||
if cursor and after is None:
|
||||
return ErrorType.INVALID_INPUT, [], None
|
||||
viewer = user.user_id if user else None
|
||||
err, rows = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.page(s, viewer, cursor, PAGE))
|
||||
sido = region_code[:2] if region_code else None
|
||||
err, rows = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.page(s, viewer, sido, int(LOCAL_BOOST.total_seconds()), after, PAGE))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return err, []
|
||||
liked: set[int] = set()
|
||||
if rows:
|
||||
ids = [t.talk_id for t, *_ in rows]
|
||||
if user is not None:
|
||||
err, liked = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.liked(s, user.user_id, ids))
|
||||
else:
|
||||
err, liked = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.anon_liked(s, ip_hash, ids))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return err, []
|
||||
return ErrorType.SUCCESS, [TalkView(talk=t, author=u, region_name=name, liked=t.talk_id in liked, mine=viewer == t.user_id) for t, u, name in rows]
|
||||
return err, [], None
|
||||
err, liked = await self._liked(user, ip_hash, [t.talk_id for t, *_ in rows])
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return err, [], None
|
||||
views = [TalkView(talk=t, author=u, region_name=name, liked=t.talk_id in liked, mine=viewer == t.user_id) for t, u, name, _ in rows]
|
||||
last = rows[-1] if len(rows) == PAGE else None
|
||||
return ErrorType.SUCCESS, spread_authors(views), f"{last[3]}_{last[0].talk_id}" if last else None
|
||||
|
||||
async def mine(self, user: User, cursor: Optional[int]) -> tuple[ErrorType, list[TalkView], Optional[int]]:
|
||||
err, rows = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.mine(s, user.user_id, cursor, PAGE))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return err, [], None
|
||||
err, liked = await self._liked(user, "", [t.talk_id for t, _ in rows])
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return err, [], None
|
||||
views = [TalkView(talk=t, author=user, region_name=name, liked=t.talk_id in liked, mine=True) for t, name in rows]
|
||||
return ErrorType.SUCCESS, views, rows[-1][0].talk_id if len(rows) == PAGE else None
|
||||
|
||||
async def _liked(self, user: Optional[User], ip_hash: str, ids: list[int]) -> tuple[ErrorType, set[int]]:
|
||||
if not ids:
|
||||
return ErrorType.SUCCESS, set()
|
||||
if user is not None:
|
||||
return await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.liked(s, user.user_id, ids))
|
||||
return await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.anon_liked(s, ip_hash, ids))
|
||||
|
||||
async def _weather_now(self, region_code: str) -> Optional[str]:
|
||||
"""지금 시각에 가장 가까운 예보 한 칸. 못 읽으면 날씨 없이 쓴다."""
|
||||
|
||||
Reference in new issue
Block a user