From cb013fcc9a3a9157ecff08e16e3a033762adca93 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Wed, 28 Oct 2026 16:06:01 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=A3=BC=20=EA=B8=88=EC=A0=84?= =?UTF-8?q?=C2=B7=EC=9D=BC=EC=9D=80=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC?= =?UTF-8?q?=EC=97=90=20=EC=A0=95=ED=95=A0=20=EB=82=A0=EB=A1=9C,=20?= =?UTF-8?q?=EC=98=AC=ED=95=B4=20=EC=9A=B4=EC=97=90=20=EC=9E=98=20=EB=A7=9E?= =?UTF-8?q?=EB=8A=94=20=EB=8B=AC,=20=EB=A0=88=EB=B2=A8=EC=97=85=20?= =?UTF-8?q?=EC=B0=BD=EC=97=90=EC=84=9C=20=EC=97=B4=EB=A6=B0=20=EC=B9=B8?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EB=A1=9C=20=EA=B0=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 금전·일: 오늘 카드를 되풀이하지 않고 이번 주 중 결제·계약할 날, 돈 빌려주기 피할 날, 보고·면접 잡을 날 - 올해 운: 잘 맞는 달 3개, 11월부터는 다음 해 미리 보기 - 레벨업 창 '…보러 가기' → /saju#칸, 내 레벨 창의 각 모으는 일 줄을 누르면 그 화면으로 - 궁합 결과에 상대 생일과 다른 사람 보기 --- backend/router/v1/saju/protocol.py | 5 +-- backend/router/v1/saju/saju.py | 2 +- backend/services/saju_service.py | 50 +++++++++++++++++++++++++++--- backend/tests/test_saju_api.py | 4 +-- frontend/src/b/SajuPage.tsx | 39 ++++++++++++++++------- frontend/src/b/level.tsx | 37 +++++++++++++++++++--- shared/api/client/types.gen.ts | 12 +++++-- 7 files changed, 121 insertions(+), 28 deletions(-) diff --git a/backend/router/v1/saju/protocol.py b/backend/router/v1/saju/protocol.py index 6bfd225..1a7f4d5 100644 --- a/backend/router/v1/saju/protocol.py +++ b/backend/router/v1/saju/protocol.py @@ -90,6 +90,7 @@ class SajuPeriod(WebPacketProtocol): title: str body: str notes: list[str] = [] + months: list[int] = Field([], description="올해: 잘 맞는 달 (양력 달)") class SajuLock(WebPacketProtocol): @@ -103,8 +104,8 @@ class Res_Saju(Res_WebPacketProtocol): me: Optional[SajuMe] = None today: Optional[SajuToday] = None week: Optional[list[SajuDay]] = Field(None, description="레벨 2부터") - money: Optional[str] = Field(None, description="레벨 3부터") - work: Optional[str] = None + money: Optional[list[str]] = Field(None, description="레벨 3부터: 이번 주 돈을 정할 날·피할 날") + work: Optional[list[str]] = None love: Optional[SajuLove] = Field(None, description="레벨 4부터") month: Optional[SajuPeriod] = Field(None, description="레벨 6부터") year: Optional[SajuPeriod] = Field(None, description="레벨 7부터") diff --git a/backend/router/v1/saju/saju.py b/backend/router/v1/saju/saju.py index 9c0a1aa..dcdc06e 100644 --- a/backend/router/v1/saju/saju.py +++ b/backend/router/v1/saju/saju.py @@ -42,7 +42,7 @@ def _res(r: Reading) -> Res_Saju: love=SajuLove(good=SajuLoveDay(**r.love["good"]) if r.love.get("good") else None, caution=SajuLoveDay(**r.love["caution"]) if r.love.get("caution") else None, gender_known=r.love.get("gender") is not None) if r.love else None, month=SajuPeriod(label=f"이달 · {r.month['from']:%-m/%-d} {r.month['jeol']} ~ {r.month['until']:%-m/%-d}", **{k: r.month[k] for k in ("pillar", "ten_god", "title", "body", "notes")}) if r.month else None, - year=SajuPeriod(label=f"{r.year['year']}년", **{k: r.year[k] for k in ("pillar", "ten_god", "title", "body", "notes")}) if r.year else None, + year=SajuPeriod(label=f"{r.year['year']}년" + (" 미리 보기" if r.year["preview"] else ""), months=r.year["months"], **{k: r.year[k] for k in ("pillar", "ten_god", "title", "body", "notes")}) if r.year else None, level=r.level, logged_in=r.logged_in, locks=[SajuLock(key=k, name=n, level=lv, unlocked=r.logged_in and r.level >= lv) for lv, items in UNLOCKS.items() for k, n in items], ) diff --git a/backend/services/saju_service.py b/backend/services/saju_service.py index f35b6f9..c403b74 100644 --- a/backend/services/saju_service.py +++ b/backend/services/saju_service.py @@ -14,7 +14,7 @@ from crud.week_crud import WeekCRUD from services import saju_text as T from services.level_service import award, level_of, unlock_level from services.saju.climate import HourWeather, chart_climate, climate_match -from services.saju.daily import DailyFacts, daily_facts, interactions +from services.saju.daily import DailyFacts, daily_facts, interactions, score as pillar_score from services.saju.ganji import branch_element, ko, stem_element from services.saju.pillars import Chart, Pillar, make_chart from services.saju.rules import branch_relations, stem_relations, ten_god @@ -254,6 +254,42 @@ def love_week(chart: Chart, week: list[DayReading], gender: Optional[Gender]) -> return out +MONEY_GOOD, MONEY_BAD, WORK_GOOD = ("편재", "정재"), ("비견", "겁재"), ("정관", "편관", "정인", "상관") + + +def _day_word(r: DayReading) -> str: + return f"{_WEEKDAY[r.day.weekday()]} {r.day.day}일({T.TEN_GOD_TEXT[r.facts.stem_ten_god][0]})" + + +def money_work(week: list[DayReading]) -> tuple[list[str], list[str]]: + """금전·일: 이번 주에 정할 날과 피할 날 (오늘 카드를 되풀이하지 않는다)""" + def pick(gods: tuple[str, ...]) -> Optional[DayReading]: + return next((r for r in week if r.facts.stem_ten_god in gods), None) + + money, work = [], [] + if (g := pick(MONEY_GOOD)) is not None: + money.append(f"큰 결제·계약은 {_day_word(g)}에 하세요.") + if (b := pick(MONEY_BAD)) is not None: + money.append(f"돈 빌려주기·공동 지출은 {_day_word(b)}엔 피하세요.") + if (w := pick(WORK_GOOD)) is not None: + work.append(f"보고·발표·면접은 {_day_word(w)}에 잡으세요.") + if not money: + money.append("이번 주는 돈이 크게 움직이는 날이 없어요. 평소대로 쓰세요.") + if not work: + work.append("이번 주는 하던 일을 마무리하기 좋아요.") + return money, work + + +def year_months(chart: Chart, year: int) -> list[int]: + """그해 열두 달(절 기준) 중 내 사주와 잘 맞는 달 셋 (달 번호는 그 절이 드는 양력 달)""" + scored = [] + for m in range(1, 13): + mp = make_chart(date(year, m, 15), time(12, 0)).month + found = interactions(chart, mp) + scored.append((pillar_score(chart, mp, found, [], False)[0], m)) + return sorted(m for _, m in sorted(scored, reverse=True)[:3]) + + def period(chart: Chart, p: Pillar, unit: str) -> dict: """이달·올해: 그 간지 천간 십성 + 원국과의 관계""" god = ten_god(chart.day.stem, p.stem) @@ -338,6 +374,12 @@ class SajuService: m = climate_match(chart, w.hours) return DayReading(day=d, facts=facts, weather=w, climate_score=m.score, best_hours=m.best_hours, reasons=m.reasons, score=total_score(facts.score, m.score)) + def _year(self, chart: Chart, today: date) -> dict: + """올해 운. 11월부터는 다음 해 미리 보기 (입춘 뒤 날짜로 그해 간지)""" + y = today.year + 1 if today.month >= 11 else today.year + p = make_chart(date(y, 6, 1), time(12, 0)).year + return {**period(chart, p, "해"), "year": y, "preview": y != today.year, "months": year_months(chart, y)} + async def match( self, me: tuple[date, Optional[time], float], friend: tuple[date, Optional[time], float], region_code: str, user: Optional[User], ) -> tuple[ErrorType, Optional[Match]]: @@ -390,10 +432,10 @@ class SajuService: chart=chart, scene=scene, scene_icon=T.SCENE_ICON.get(chart_climate.label, "sun") if chart_climate else "sun", need=[T.NEED_WORD[n] for n in needs], today=r0, cards=cards, why=why_words(r0.facts), level=level, logged_in=user is not None, week=days if unlocked("saju_week") else None, - money=T.MONEY_TEXT[r0.facts.stem_ten_god] if unlocked("saju_money") else None, - work=T.WORK_TEXT[r0.facts.stem_ten_god] if unlocked("saju_money") else None, + money=money_work(days)[0] if unlocked("saju_money") else None, + work=money_work(days)[1] if unlocked("saju_money") else None, love=love_week(chart, days, gender) if unlocked("saju_love") else None, month={**period(chart, now_chart.month, "달"), "from": now_chart.jeol.at.date(), "until": now_chart.next_jeol.at.date(), "jeol": now_chart.jeol.name} if unlocked("saju_month") else None, - year={**period(chart, now_chart.year, "해"), "year": today.year} if unlocked("saju_year") else None, + year=self._year(chart, today) if unlocked("saju_year") else None, ) diff --git a/backend/tests/test_saju_api.py b/backend/tests/test_saju_api.py index d5b6dfd..27bbfc2 100644 --- a/backend/tests/test_saju_api.py +++ b/backend/tests/test_saju_api.py @@ -61,14 +61,14 @@ async def test_level_unlocks_sections_and_awards_once(offline): r = (await c.post("/v1/saju/reading", json={**BIRTH, "gender": "male"}, headers=h4)).json() assert r["level"] == 4 assert len(r["week"]) == 7 and sum(d["best"] for d in r["week"]) == 1 - assert r["money"] and r["work"] and r["love"]["gender_known"] is True + assert r["money"] and r["work"] and all(isinstance(x, str) for x in r["money"]) and r["love"]["gender_known"] is True assert "month" not in r and "year" not in r unlocked = {x["key"]: x["unlocked"] for x in r["locks"]} assert unlocked["saju_love"] and not unlocked["saju_match"] h7 = await _login(c, "saju_07", points=1000) r = (await c.post("/v1/saju/reading", json=BIRTH, headers=h7)).json() - assert r["month"]["title"].endswith("달") and r["year"]["label"].endswith("년") + assert r["month"]["title"].endswith("달") and "년" in r["year"]["label"] and len(r["year"]["months"]) == 3 @pytest.mark.anyio diff --git a/frontend/src/b/SajuPage.tsx b/frontend/src/b/SajuPage.tsx index 534defa..bc251e8 100644 --- a/frontend/src/b/SajuPage.tsx +++ b/frontend/src/b/SajuPage.tsx @@ -136,6 +136,11 @@ function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) { const { open } = useSheet() const r = q.data + useEffect(() => { + if (!r?.today || !window.location.hash) return + document.getElementById(window.location.hash.slice(1))?.scrollIntoView({ behavior: 'smooth', block: 'start' }) + }, [r]) + useEffect(() => { if (!r?.today) return markSeen() @@ -186,15 +191,18 @@ function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) { {r.week && } {r.money && ( - -

💰 {r.money}

-

💼 {r.work}

+ + {[...r.money.map((l) => ['💰', l]), ...(r.work ?? []).map((l) => ['💼', l])].map(([icon, l]) => ( +

+ {icon} {l} +

+ ))}
)} {r.love && } {lock('saju_match')?.unlocked && } - {r.month && } - {r.year && } + {r.month && } + {r.year && } !l.unlocked)} />
@@ -264,9 +272,9 @@ function Char({ c, ko, el }: { c: string; ko: string; el: string }) { ) } -function Panel({ icon, title, right, children }: { icon: string; title: string; right?: ReactNode; children: ReactNode }) { +function Panel({ id, icon, title, right, children }: { id?: string; icon: string; title: string; right?: ReactNode; children: ReactNode }) { return ( -
+

{title}

@@ -317,7 +325,7 @@ function Locked({ locks }: { locks: SajuLock[] }) { function Week({ r }: { r: ResSaju }) { return ( - +
    {r.week!.map((d) => (
  1. @@ -340,7 +348,7 @@ function Love({ r, birth }: { r: ResSaju; birth: Birth }) { const love = r.love! const pick = (g: 'M' | 'F' | null) => setBirth({ ...birth, gender: g }) return ( - + {love.good ? (

    연애 기운 좋은 날

    @@ -373,13 +381,14 @@ function Love({ r, birth }: { r: ResSaju; birth: Birth }) { ) } -function Period({ icon, p }: { icon: string; p: NonNullable }) { +function Period({ id, icon, p }: { id: string; icon: string; p: NonNullable }) { return ( - +

    {p.title} ({p.pillar} · {p.ten_god})

    {p.body}

    + {(p.months?.length ?? 0) > 0 &&

    잘 맞는 달: {p.months!.map((m) => `${m}월`).join(' · ')}

    } {(p.notes?.length ?? 0) > 0 &&

    {p.notes!.join(' · ')}

    }
    ) @@ -401,9 +410,15 @@ function Match({ birth }: { birth: Birth }) { run.mutate({ body: { region_code: region.code, me: toBody(birth), friend: { birth_date: `${yy}-${String(mm).padStart(2, '0')}-${String(dd).padStart(2, '0')}`, longitude: 126.98 } } }) } return ( - + {res ? ( <> +

    + 상대 {y}.{m}.{d}생 + +

    {res.title} {res.score}

    diff --git a/frontend/src/b/level.tsx b/frontend/src/b/level.tsx index 8b3db6a..cf518ff 100644 --- a/frontend/src/b/level.tsx +++ b/frontend/src/b/level.tsx @@ -1,4 +1,5 @@ import { useEffect, useRef } from 'react' +import { useNavigate } from 'react-router' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { attendMutation, myLevelOptions, myLevelQueryKey, sharedMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen' import type { ResLevel } from '@nalssigak/shared/api/client/types.gen' @@ -8,6 +9,20 @@ import { HIDDEN } from './features' import { useSheet } from './sheetContext' import { Ic } from './ui' +// 각을 주는 일 → 그 일을 하러 가는 곳, 숨긴 기능에 딸린 일 (서버 ACTIONS 키) +const ACTION_TO: Record = { saju: '/saju', react: '/', talk: '/talk' } +const ACTION_FEATURE: Record = { tarot: 'tarot', checkin: 'tarot' } + +// 창이 쌓아 둔 방문 기록을 닫으며 되돌리므로, 되돌린 뒤(popstate)에 이동해야 새 주소가 안 지워진다 +function useCloseAndGo() { + const { close } = useSheet() + const navigate = useNavigate() + return (to: string) => { + window.addEventListener('popstate', () => navigate(to), { once: true }) + close() + } +} + // 레벨마다 보여 줄 하늘 아이콘 (이름은 서버 LEVELS) const LEVEL_ICON = ['droplet', 'sun', 'leaf', 'rainbow', 'sunset', 'milky_way', 'shooting_star'] export const levelIcon = (level: number) => LEVEL_ICON[Math.min(Math.max(level, 1), LEVEL_ICON.length) - 1] @@ -126,6 +141,7 @@ export function LevelCard({ link = true }: { link?: boolean }) { /** 내 레벨 창: 오늘 받을 수 있는 각, 레벨마다 열리는 것 */ export function LevelSheet() { const level = useLevel().data + const go = useCloseAndGo() if (!level) return null const steps = (level.unlocks ?? []).reduce>((m, u) => ({ ...m, [u.level]: [...(m[u.level] ?? []), u.name] }), {}) return ( @@ -134,15 +150,21 @@ export function LevelSheet() {

    오늘 받을 수 있는 각

      - {(level.today ?? []).filter((a) => !HIDDEN.has(a.action)).map((a) => { + {(level.today ?? []).filter((a) => !HIDDEN.has(ACTION_FEATURE[a.action] ?? a.action)).map((a) => { const done = a.earned >= a.cap + const to = ACTION_TO[a.action] return ( -
    • +
    • go(to) : undefined} + className={cx('flex items-center gap-2.5 border-b border-[#eef1f6] px-3.5 py-2.5 text-[13.5px] font-bold last:border-0', to && !done && 'cursor-pointer')} + > {done ? '✓' : ''} {a.name} {a.earned > 0 && a.cap > a.points ? `${a.earned}/${a.cap}` : `+${a.points}`}각 + {to && !done && ›}
    • ) })} @@ -176,7 +198,9 @@ export function LevelSheet() { export function LevelUpSheet({ level: lv }: { level: number }) { const level = useLevel().data const { open } = useSheet() - const opened = (level?.unlocks ?? []).filter((u) => u.level === lv).map((u) => u.name) + const go = useCloseAndGo() + const unlocks = (level?.unlocks ?? []).filter((u) => u.level === lv) + const opened = unlocks.map((u) => u.name) const name = level?.levels?.find((l) => l.level === lv)?.name return (
      @@ -185,7 +209,12 @@ export function LevelUpSheet({ level: lv }: { level: number }) { Lv.{lv} {name} {opened.length > 0 &&

      새로 열렸어요: {opened.join(', ')}

      } - + )} +
      diff --git a/shared/api/client/types.gen.ts b/shared/api/client/types.gen.ts index d23442f..0e3d557 100644 --- a/shared/api/client/types.gen.ts +++ b/shared/api/client/types.gen.ts @@ -2947,13 +2947,13 @@ export type ResSaju = { /** * Money * - * 레벨 3부터 + * 레벨 3부터: 이번 주 돈을 정할 날·피할 날 */ - money?: string | null; + money?: Array | null; /** * Work */ - work?: string | null; + work?: Array | null; /** * 레벨 4부터 */ @@ -3730,6 +3730,12 @@ export type SajuPeriod = { * Notes */ notes?: Array; + /** + * Months + * + * 올해: 잘 맞는 달 (양력 달) + */ + months?: Array; }; /**