[changes] AI reviews and modifies the code

This commit is contained in:
lanceyq
2026-03-03 15:16:47 +08:00
parent 6033d37537
commit 7446241735
9 changed files with 114 additions and 188 deletions

View File

@@ -262,7 +262,6 @@ async def check_emotion_data_exists(
@router.post("/suggestions", response_model=ApiResponse)
async def get_emotion_suggestions(
request: EmotionSuggestionsRequest,
language_type: str = Header(default=None, alias="X-Language-Type"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
@@ -277,9 +276,6 @@ async def get_emotion_suggestions(
存储的个性化情绪建议响应
"""
try:
# 使用集中化的语言校验
language = get_language_from_header(language_type)
api_logger.info(
f"用户 {current_user.username} 请求获取个性化情绪建议",
extra={
@@ -295,15 +291,13 @@ async def get_emotion_suggestions(
)
if data is None:
# 数据不存在,返回提示信息
api_logger.info(
f"用户 {request.end_user_id} 的建议数据不存在",
extra={"end_user_id": request.end_user_id}
)
return fail(
BizCode.NOT_FOUND,
"情绪建议数据不存在,请点击右上角刷新进行初始化",
""
return success(
data={"exists": False},
msg="情绪建议数据不存在,请点击右上角刷新进行初始化"
)
api_logger.info(

View File

@@ -152,10 +152,9 @@ async def check_user_data_exists(
if cached_profile is None:
api_logger.info(f"用户 {end_user_id} 的画像数据不存在")
return fail(
BizCode.NOT_FOUND,
"画像数据不存在,请点击右上角刷新进行初始化",
{"exists": False}
return success(
data={"exists": False},
msg="画像数据不存在,请点击右上角刷新进行初始化"
)
api_logger.info(f"用户 {end_user_id} 的画像数据存在")
@@ -203,11 +202,7 @@ async def get_preference_tags(
if cached_profile is None:
api_logger.info(f"用户 {end_user_id} 的画像数据不存在")
return fail(
BizCode.NOT_FOUND,
"画像数据不存在,请点击右上角刷新进行初始化",
""
)
return fail(BizCode.NOT_FOUND, "", "")
# Extract preferences from cache
preferences = cached_profile.get("preferences", [])
@@ -274,11 +269,7 @@ async def get_dimension_portrait(
if cached_profile is None:
api_logger.info(f"用户 {end_user_id} 的画像数据不存在")
return fail(
BizCode.NOT_FOUND,
"画像数据不存在,请点击右上角刷新进行初始化",
""
)
return fail(BizCode.NOT_FOUND, "", "")
# Extract portrait from cache
portrait = cached_profile.get("portrait", {})
@@ -322,11 +313,7 @@ async def get_interest_area_distribution(
if cached_profile is None:
api_logger.info(f"用户 {end_user_id} 的画像数据不存在")
return fail(
BizCode.NOT_FOUND,
"画像数据不存在,请点击右上角刷新进行初始化",
""
)
return fail(BizCode.NOT_FOUND, "", "")
# Extract interest areas from cache
interest_areas = cached_profile.get("interest_areas", {})
@@ -374,11 +361,7 @@ async def get_behavior_habits(
if cached_profile is None:
api_logger.info(f"用户 {end_user_id} 的画像数据不存在")
return fail(
BizCode.NOT_FOUND,
"画像数据不存在,请点击右上角刷新进行初始化",
""
)
return fail(BizCode.NOT_FOUND, "", "")
# Extract habits from cache
habits = cached_profile.get("habits", [])