Skip to content

Commit 47bf1b8

Browse files
9keyyyyGukhee Jo
andauthored
fix: fortune details type 지정 (#18)
Co-authored-by: Gukhee Jo <[email protected]>
1 parent 9e7b882 commit 47bf1b8

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

src/fortune/entities/enums.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ class FortuneType(str, Enum):
88
LUCKY_OBJECT = "행운의 오브제"
99
PERFECT_TIMING = "절호의 타이밍"
1010
TABOO_OF_DAY = "오늘의 금기"
11+
12+
13+
class FortuneDetailType(str, Enum):
14+
"""운세 상세 항목 타입"""
15+
MONEY = "money"
16+
JOB = "job"
17+
LOVE = "love"

src/fortune/entities/schemas.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import date
33
from typing import List, Optional, Dict
44
from src.config.schemas import CommonBase
5-
from src.fortune.entities.enums import FortuneType
5+
from src.fortune.entities.enums import FortuneType, FortuneDetailType
66

77

88
class DailyFortuneResource(CommonBase):
@@ -39,10 +39,18 @@ class UserDailyFortuneSummary(CommonBase):
3939
image_url: str
4040
description: str
4141

42+
43+
class FortuneDetailItem(CommonBase):
44+
"""운세 상세 항목"""
45+
type: FortuneDetailType
46+
title: str
47+
content: str
48+
49+
4250
class UserDailyFortuneDetail(CommonBase):
4351
id: int
4452
user_id: str
4553
fortune_date: date
4654
fortune_score: int
4755
fortune_comment: str
48-
fortune_details: Dict[str, str]
56+
fortune_details: List[FortuneDetailItem]

src/fortune/repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ async def create_user_daily_fortune_detail(
159159
fortune_date: date,
160160
fortune_score: int,
161161
fortune_comment: str,
162-
fortune_details: dict,
162+
fortune_details: List[dict],
163163
) -> UserDailyFortuneDetailModel:
164164
"""사용자 운세 상세 정보 생성"""
165165
model = UserDailyFortuneDetailModel(

src/fortune/service.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
from fastapi import Depends, HTTPException, status
55

6-
from src.fortune.entities.enums import FortuneType
6+
from src.fortune.entities.enums import FortuneType, FortuneDetailType
77
from src.fortune.entities.schemas import (
88
DailyFortuneResource,
99
DailyFortuneResourceCreate,
1010
DailyFortuneResourceUpdate,
1111
DailyFortuneResourceList,
1212
UserDailyFortuneDetail,
13+
FortuneDetailItem,
1314
)
1415
from src.fortune.entities.schemas import UserDailyFortuneSummary
1516
from src.fortune.repository import FortuneRepository
@@ -112,6 +113,8 @@ async def get_user_daily_fortune_detail(
112113
# 2. 기존 정보가 없으면 HCX API 호출하여 생성
113114
return await self._create_daily_fortune_detail(user_id, fortune_date)
114115

116+
117+
115118
async def _create_daily_fortune_detail(
116119
self, user_id: str, fortune_date: date
117120
) -> UserDailyFortuneDetail:
@@ -166,19 +169,32 @@ async def _create_daily_fortune_detail(
166169
fortune_data = DAILY_FORTUNE_FALLBACK_DATA
167170

168171
# 4. fortune_details 구성
169-
fortune_details = {
170-
"재물운": fortune_data.get("money_fortune", ""),
171-
"취업운": fortune_data.get("job_fortune", ""),
172-
"연애운": fortune_data.get("love_fortune", ""),
173-
}
172+
fortune_details = [
173+
FortuneDetailItem(
174+
type=FortuneDetailType.MONEY,
175+
title="재물운",
176+
content=fortune_data.get("money_fortune", "")
177+
),
178+
FortuneDetailItem(
179+
type=FortuneDetailType.JOB,
180+
title="취업운",
181+
content=fortune_data.get("job_fortune", "")
182+
),
183+
FortuneDetailItem(
184+
type=FortuneDetailType.LOVE,
185+
title="연애운",
186+
content=fortune_data.get("love_fortune", "")
187+
)
188+
]
174189

175-
# 5. DB에 저장
190+
# 5. DB에 저장 (FortuneDetailItem을 dict로 변환)
191+
fortune_details_dict = [detail.model_dump() for detail in fortune_details]
176192
model = await self.repository.create_user_daily_fortune_detail(
177193
user_id=user_id,
178194
fortune_date=fortune_date,
179195
fortune_score=fortune_data.get("score", 0),
180196
fortune_comment=fortune_data.get("comment", ""),
181-
fortune_details=fortune_details,
197+
fortune_details=fortune_details_dict,
182198
)
183199

184200
return UserDailyFortuneDetail.model_validate(model)

0 commit comments

Comments
 (0)