Merge remote-tracking branch 'origin/main' into feat/weather-game
# Conflicts: # shared/api/client/@tanstack/react-query.gen.ts # shared/api/client/index.ts # shared/api/client/sdk.gen.ts # shared/api/client/types.gen.ts
This commit is contained in:
commit
9e7bd54c7e
48 files changed
+3253
-189
No files matched your search
@@ -16,6 +16,7 @@ from router.v1.index.index import router as index_router
|
||||
from router.v1.my_gak.my_gak import router as my_gak_router
|
||||
from router.v1.fortune.fortune import router as fortune_router
|
||||
from router.v1.level.level import router as level_router
|
||||
from router.v1.saju.saju import router as saju_router
|
||||
from router.v1.reaction.reaction import router as reaction_router
|
||||
from router.v1.region.region import router as region_router
|
||||
from router.v1.season.season import router as season_router
|
||||
@@ -52,6 +53,7 @@ app.include_router(reaction_router)
|
||||
app.include_router(my_gak_router)
|
||||
app.include_router(fortune_router)
|
||||
app.include_router(level_router)
|
||||
app.include_router(saju_router)
|
||||
app.include_router(talk_router)
|
||||
app.include_router(watch_router)
|
||||
app.include_router(image_router)
|
||||
|
||||
@@ -14,7 +14,7 @@ from common.models.errors import error_info
|
||||
from common.utils.kma_time import KST, kst_midnight, now_kst
|
||||
from crud.card_crud import CardCRUD
|
||||
from crud.feed_crud import FeedCRUD
|
||||
from router.v1.card.protocol import CardItem, Req_CardCreate, Res_Card, Res_CardList, Res_LatestCard
|
||||
from router.v1.card.protocol import CardItem, Req_CardCreate, Res_Card, Res_CardList
|
||||
from services.bot_comment import fill_bot_comments
|
||||
from services.external import instagram
|
||||
from services.feed_service import _FEED_DAY_START, clear_feed_cache, feed_day
|
||||
@@ -82,16 +82,6 @@ async def list_cards(limit: int = Query(50, ge=1, le=200)) -> Res_CardList:
|
||||
])
|
||||
|
||||
|
||||
@router.get("/latest", response_model=Res_LatestCard, response_model_exclude_none=True, summary="그 틀로 가장 최근에 피드에 올린 카드뉴스의 포스트 (오늘 탭 '오늘 코디' 아이콘)")
|
||||
async def latest_card(template: str = Query(..., pattern=r"^[a-z_]{1,20}$")) -> Res_LatestCard:
|
||||
err, card = await DB_SESSION_MNG.execute_lambda(lambda s: _crud.latest_published(s, template))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return Res_LatestCard(result=error_info(err))
|
||||
if card is None:
|
||||
return Res_LatestCard()
|
||||
return Res_LatestCard(post_id=card.post_id, published_at=card.published_at.astimezone(KST) if card.published_at else None)
|
||||
|
||||
|
||||
@router.post("", response_model=Res_Card, response_model_exclude_none=True, summary="카드뉴스 저장 (관리자). publish 면 바로 그날 피드에 올린다", dependencies=[Depends(require_admin)])
|
||||
async def create_card(req: Req_CardCreate) -> Res_Card:
|
||||
images = _jpegs(req.images)
|
||||
|
||||
@@ -18,11 +18,6 @@ class Req_CardCreate(WebPacketProtocol):
|
||||
publish: bool = Field(default=False, description="true 면 만들자마자 그날 피드에 올린다. false 면 승인 대기")
|
||||
|
||||
|
||||
class Res_LatestCard(Res_WebPacketProtocol):
|
||||
post_id: Optional[int] = None
|
||||
published_at: Optional[datetime] = None
|
||||
|
||||
|
||||
class Res_Card(Res_WebPacketProtocol):
|
||||
card_id: Optional[int] = None
|
||||
status: Optional[CardStatus] = None
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,134 @@
|
||||
from datetime import date
|
||||
from typing import Literal, Optional
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from common.models.gmodel import Req_WebPacketProtocol, Res_WebPacketProtocol, WebPacketProtocol
|
||||
|
||||
|
||||
class Req_Saju(Req_WebPacketProtocol):
|
||||
region_code: str = Field(min_length=10, max_length=10)
|
||||
birth_date: date = Field(description="양력 생년월일 (1900-01-01 ~ 오늘)")
|
||||
birth_time: Optional[str] = Field(None, pattern=r"^([01]\d|2[0-3]):[0-5]\d$", description="태어난 시각 HH:MM (모르면 없음)")
|
||||
longitude: float = Field(126.98, ge=124, le=132, description="태어난 곳 경도 (시각 보정)")
|
||||
gender: Optional[Literal["male", "female"]] = Field(None, description="연애운에서 이성 기운을 볼 때만")
|
||||
|
||||
|
||||
class SajuPillar(WebPacketProtocol):
|
||||
position: str = Field(description="year·month·day·hour")
|
||||
stem: str
|
||||
branch: str
|
||||
stem_ko: str
|
||||
branch_ko: str
|
||||
stem_element: str = Field(description="木火土金水")
|
||||
branch_element: str
|
||||
|
||||
|
||||
class SajuMe(WebPacketProtocol):
|
||||
pillars: list[SajuPillar]
|
||||
hour_known: bool
|
||||
jeol_warning: bool = Field(description="시각을 모르는데 태어난 날 절이 들어 연·월주가 갈릴 수 있음")
|
||||
scene: str = Field(description="내 기운 이름 (예: 봄비 기운)")
|
||||
scene_desc: str
|
||||
scene_icon: str
|
||||
season: Optional[str] = None
|
||||
climate: Optional[str] = Field(None, description="따뜻·마름 / 따뜻·촉촉 / 서늘·마름 / 서늘·촉촉")
|
||||
need: list[str] = Field([], description="내 기운에 필요한 것 (따뜻함·마른 공기 등)")
|
||||
|
||||
|
||||
class SajuCard(WebPacketProtocol):
|
||||
kind: str = Field(description="when·do·avoid·good·wear")
|
||||
title: str
|
||||
body: str
|
||||
sub: Optional[str] = None
|
||||
|
||||
|
||||
class SajuToday(WebPacketProtocol):
|
||||
day: date
|
||||
pillar: str = Field(description="오늘 간지 한글 (을해)")
|
||||
ten_god: str
|
||||
title: str
|
||||
score: int = Field(description="오늘 점수 = 사주 + 날씨 궁합")
|
||||
saju_score: int
|
||||
weather_points: Optional[int] = Field(None, description="날씨 궁합이 더하거나 뺀 점수")
|
||||
why: list[str] = Field([], description="점수에 크게 작용한 사실")
|
||||
cards: list[SajuCard]
|
||||
|
||||
|
||||
class SajuDay(WebPacketProtocol):
|
||||
day: date
|
||||
weekday: str
|
||||
icon: Optional[str] = None
|
||||
word: Optional[str] = None
|
||||
temp_min: Optional[int] = None
|
||||
temp_max: Optional[int] = None
|
||||
score: int
|
||||
title: str
|
||||
best: bool = False
|
||||
|
||||
|
||||
class SajuLoveDay(WebPacketProtocol):
|
||||
day: date
|
||||
weekday: str
|
||||
icon: Optional[str] = None
|
||||
word: Optional[str] = None
|
||||
temp_max: Optional[int] = None
|
||||
body: str
|
||||
why: str
|
||||
|
||||
|
||||
class SajuLove(WebPacketProtocol):
|
||||
good: Optional[SajuLoveDay] = None
|
||||
caution: Optional[SajuLoveDay] = None
|
||||
gender_known: bool
|
||||
|
||||
|
||||
class SajuPeriod(WebPacketProtocol):
|
||||
label: str = Field(description="이달 · 10/8 한로 ~ 11/7 / 2026년")
|
||||
pillar: str
|
||||
ten_god: str
|
||||
title: str
|
||||
body: str
|
||||
notes: list[str] = []
|
||||
months: list[int] = Field([], description="올해: 잘 맞는 달 (양력 달)")
|
||||
|
||||
|
||||
class SajuLock(WebPacketProtocol):
|
||||
key: str
|
||||
name: str
|
||||
level: int
|
||||
unlocked: bool
|
||||
|
||||
|
||||
class Res_Saju(Res_WebPacketProtocol):
|
||||
me: Optional[SajuMe] = None
|
||||
today: Optional[SajuToday] = None
|
||||
week: Optional[list[SajuDay]] = Field(None, description="레벨 2부터")
|
||||
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부터")
|
||||
level: int = 1
|
||||
logged_in: bool = False
|
||||
locks: list[SajuLock] = []
|
||||
|
||||
|
||||
class SajuBirth(WebPacketProtocol):
|
||||
birth_date: date
|
||||
birth_time: Optional[str] = Field(None, pattern=r"^([01]\d|2[0-3]):[0-5]\d$")
|
||||
longitude: float = Field(126.98, ge=124, le=132)
|
||||
|
||||
|
||||
class Req_SajuMatch(Req_WebPacketProtocol):
|
||||
region_code: str = Field(min_length=10, max_length=10)
|
||||
me: SajuBirth
|
||||
friend: SajuBirth
|
||||
|
||||
|
||||
class Res_SajuMatch(Res_WebPacketProtocol):
|
||||
score: Optional[int] = None
|
||||
title: Optional[str] = None
|
||||
lines: list[str] = []
|
||||
friend_scene: Optional[str] = Field(None, description="친구의 기운 이름")
|
||||
day: Optional[SajuDay] = Field(None, description="이번 주 둘 다 좋은 날")
|
||||
@@ -0,0 +1,73 @@
|
||||
from datetime import time
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from common.auth import optional_user
|
||||
from common.database.model.models import User
|
||||
from common.enums import ErrorType
|
||||
from common.models.errors import error_info
|
||||
from router.v1.saju.protocol import Req_Saju, Req_SajuMatch, Res_Saju, Res_SajuMatch, SajuBirth, SajuCard, SajuDay, SajuLock, SajuLove, SajuLoveDay, SajuMe, SajuPeriod, SajuPillar, SajuToday
|
||||
from services import saju_text as T
|
||||
from services.level_service import UNLOCKS
|
||||
from services.saju.ganji import branch_element, ko, stem_element
|
||||
from services.saju_service import Reading, SajuService, shown_saju, weather_points
|
||||
|
||||
router = APIRouter(prefix="/v1/saju", tags=["saju"])
|
||||
_WEEKDAY = "월화수목금토일"
|
||||
|
||||
|
||||
def _res(r: Reading) -> Res_Saju:
|
||||
c = r.chart
|
||||
pillars = [("year", c.year), ("month", c.month), ("day", c.day)] + ([("hour", c.hour)] if c.hour else [])
|
||||
today = r.today
|
||||
best = max(r.week, key=lambda d: d.score).day if r.week else None
|
||||
return Res_Saju(
|
||||
me=SajuMe(
|
||||
pillars=[SajuPillar(position=pos, stem=p.stem, branch=p.branch, stem_ko=ko(p.stem), branch_ko=ko(p.branch), stem_element=stem_element(p.stem), branch_element=branch_element(p.branch)) for pos, p in pillars],
|
||||
hour_known=c.hour is not None, jeol_warning=c.jeol_on_birth_day, scene=r.scene[0], scene_desc=r.scene[1], scene_icon=r.scene_icon, need=r.need,
|
||||
),
|
||||
today=SajuToday(
|
||||
day=today.day, pillar=ko(today.facts.pillar.stem + today.facts.pillar.branch), ten_god=today.facts.stem_ten_god, title=T.TEN_GOD_TEXT[today.facts.stem_ten_god][0],
|
||||
score=today.score, saju_score=shown_saju(today.facts.score), weather_points=weather_points(today.climate_score),
|
||||
why=r.why, cards=[SajuCard(**x.__dict__) for x in r.cards],
|
||||
),
|
||||
week=[
|
||||
SajuDay(day=d.day, weekday=_WEEKDAY[d.day.weekday()], icon=d.weather.icon if d.weather else None, word=d.weather.word if d.weather else None,
|
||||
temp_min=d.weather.temp_min if d.weather else None, temp_max=d.weather.temp_max if d.weather else None,
|
||||
score=d.score, title=T.TEN_GOD_TEXT[d.facts.stem_ten_god][0], best=d.day == best)
|
||||
for d in r.week
|
||||
] if r.week else None,
|
||||
money=r.money, work=r.work,
|
||||
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']}년" + (" 미리 보기" 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],
|
||||
)
|
||||
|
||||
|
||||
@router.post("/reading", response_model=Res_Saju, response_model_exclude_none=True, summary="날씨 사주: 내 기운, 오늘 점수(사주+날씨 궁합)와 할 일, 레벨로 열리는 이번 주·금전·연애·이달·올해. 생년월일은 저장하지 않는다")
|
||||
async def reading(req: Req_Saju, user: Optional[User] = Depends(optional_user), service: SajuService = Depends()) -> Res_Saju:
|
||||
t = time(*map(int, req.birth_time.split(":"))) if req.birth_time else None
|
||||
err, r = await service.reading(req.birth_date, t, req.longitude, req.gender, req.region_code, user)
|
||||
return Res_Saju(result=error_info(err)) if err is not ErrorType.SUCCESS or r is None else _res(r)
|
||||
|
||||
|
||||
def _birth(b: SajuBirth) -> tuple:
|
||||
return b.birth_date, time(*map(int, b.birth_time.split(":"))) if b.birth_time else None, b.longitude
|
||||
|
||||
|
||||
@router.post("/match", response_model=Res_SajuMatch, response_model_exclude_none=True, summary="궁합 (계정 레벨 5부터): 일간·일지·기운으로 본 사이, 이번 주 둘 다 좋은 날. 생년월일은 저장하지 않는다")
|
||||
async def match(req: Req_SajuMatch, user: Optional[User] = Depends(optional_user), service: SajuService = Depends()) -> Res_SajuMatch:
|
||||
err, m = await service.match(_birth(req.me), _birth(req.friend), req.region_code, user)
|
||||
if err is not ErrorType.SUCCESS or m is None:
|
||||
return Res_SajuMatch(result=error_info(err))
|
||||
d = m.day
|
||||
return Res_SajuMatch(
|
||||
score=m.score, title=m.title, lines=m.lines, friend_scene=m.friend_scene,
|
||||
day=SajuDay(day=d.day, weekday=_WEEKDAY[d.day.weekday()], icon=d.weather.icon if d.weather else None, word=d.weather.word if d.weather else None,
|
||||
temp_min=d.weather.temp_min if d.weather else None, temp_max=d.weather.temp_max if d.weather else None, score=d.score,
|
||||
title=T.TEN_GOD_TEXT[d.facts.stem_ten_god][0], best=True) if d else None,
|
||||
)
|
||||
Reference in new issue
Block a user