This commit is contained in:
1 parent
cf7c96eaff
commit
051452d3b1
21 files changed
+865
-311
No files matched your search
@@ -14,6 +14,21 @@ class Req_Saju(Req_WebPacketProtocol):
|
||||
gender: Optional[Literal["male", "female"]] = Field(None, description="연애운에서 이성 기운을 볼 때만")
|
||||
|
||||
|
||||
class SajuSavedBirth(WebPacketProtocol):
|
||||
birth_date: date
|
||||
birth_time: Optional[str] = Field(None, pattern=r"^([01]\d|2[0-3]):[0-5]\d$", description="HH:MM (모르면 없음)")
|
||||
place: Optional[str] = Field(None, pattern=r"^[a-z]{2,20}$", description="태어난 곳 키 (seoul 등)")
|
||||
gender: Optional[Literal["male", "female"]] = None
|
||||
|
||||
|
||||
class Req_SajuBirth(Req_WebPacketProtocol, SajuSavedBirth):
|
||||
pass
|
||||
|
||||
|
||||
class Res_SajuBirth(Res_WebPacketProtocol):
|
||||
birth: Optional[SajuSavedBirth] = None
|
||||
|
||||
|
||||
class SajuPillar(WebPacketProtocol):
|
||||
position: str = Field(description="year·month·day·hour")
|
||||
stem: str
|
||||
|
||||
@@ -3,11 +3,11 @@ from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from common.auth import optional_user
|
||||
from common.auth import current_user, 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 router.v1.saju.protocol import Req_Saju, Req_SajuBirth, Req_SajuMatch, Res_Saju, Res_SajuBirth, SajuSavedBirth, 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
|
||||
@@ -55,6 +55,31 @@ async def reading(req: Req_Saju, user: Optional[User] = Depends(optional_user),
|
||||
return Res_Saju(result=error_info(err)) if err is not ErrorType.SUCCESS or r is None else _res(r)
|
||||
|
||||
|
||||
def _saved(u: Optional[User]) -> Res_SajuBirth:
|
||||
if u is None or u.birth_date is None:
|
||||
return Res_SajuBirth()
|
||||
t = f"{u.birth_time:%H:%M}" if u.birth_time else None
|
||||
return Res_SajuBirth(birth=SajuSavedBirth(birth_date=u.birth_date, birth_time=t, place=u.birth_place, gender=u.gender))
|
||||
|
||||
|
||||
@router.get("/birth", response_model=Res_SajuBirth, response_model_exclude_none=True, summary="계정에 저장한 내 생년월일 (없으면 birth 없음)")
|
||||
async def get_birth(user: User = Depends(current_user)) -> Res_SajuBirth:
|
||||
return _saved(user)
|
||||
|
||||
|
||||
@router.put("/birth", response_model=Res_SajuBirth, response_model_exclude_none=True, summary="내 생년월일을 계정에 저장 (날씨 사주를 어느 기기에서든 바로 본다)")
|
||||
async def put_birth(req: Req_SajuBirth, user: User = Depends(current_user), service: SajuService = Depends()) -> Res_SajuBirth:
|
||||
t = time(*map(int, req.birth_time.split(":"))) if req.birth_time else None
|
||||
err, u = await service.save_birth(user, req.birth_date, t, req.place, req.gender)
|
||||
return Res_SajuBirth(result=error_info(err)) if err is not ErrorType.SUCCESS or u is None else _saved(u)
|
||||
|
||||
|
||||
@router.delete("/birth", response_model=Res_SajuBirth, response_model_exclude_none=True, summary="계정에 저장한 내 생년월일 지우기")
|
||||
async def delete_birth(user: User = Depends(current_user), service: SajuService = Depends()) -> Res_SajuBirth:
|
||||
err, _ = await service.clear_birth(user)
|
||||
return Res_SajuBirth(result=error_info(err))
|
||||
|
||||
|
||||
def _birth(b: SajuBirth) -> tuple:
|
||||
return b.birth_date, time(*map(int, b.birth_time.split(":"))) if b.birth_time else None, b.longitude
|
||||
|
||||
|
||||
Reference in new issue
Block a user