fix: 修改用户信息接口的返回值
continuous-integration/drone/push Build is passing Details

This commit is contained in:
BryantHe 2023-08-19 12:31:22 +08:00
parent 330084ea4a
commit d039cc69e1
2 changed files with 16 additions and 7 deletions

View File

@ -1,5 +1,5 @@
from apiflask import Schema from apiflask import Schema
from apiflask.fields import String, Float from apiflask.fields import String, Float, URL
class UserInfoIn(Schema): class UserInfoIn(Schema):
@ -10,4 +10,5 @@ class UserInfoIn(Schema):
class UserInfoOut(Schema): class UserInfoOut(Schema):
nickname = String() nickname = String()
avatar_id = String() avatar_id = String()
avatar_url = URL()
height = Float(allow_nan=True) height = Float(allow_nan=True)

View File

@ -2,6 +2,7 @@ from apiflask import APIBlueprint
from flask import session from flask import session
from app import rpc from app import rpc
from app.api.v1.exception.api import ImageNotFound
from app.api.v1.exception.user import UserInfoNotFound, UserInfoError from app.api.v1.exception.user import UserInfoNotFound, UserInfoError
from app.api.v1.schema.user import UserInfoIn, UserInfoOut from app.api.v1.schema.user import UserInfoIn, UserInfoOut
from app.util.auth import login_required from app.util.auth import login_required
@ -40,12 +41,19 @@ def get_user_info():
except Exception as e: except Exception as e:
raise UserInfoNotFound(extra_data={'error_docs': str(e)}) raise UserInfoNotFound(extra_data={'error_docs': str(e)})
try:
presign_url = rpc.storage.get_presign_url(user_dict['avatar_id'],
'bodyrecord',
bucket='bodyrecord')
user_dict['avatar_url'] = presign_url
except Exception as e:
raise ImageNotFound(extra_data={'error_docs': str(e)})
try: try:
body_info_dict = rpc.body_record.get_body_info(session['user_id']) body_info_dict = rpc.body_record.get_body_info(session['user_id'])
except Exception as e: except Exception as e:
raise UserInfoNotFound(extra_data={'error_docs': str(e)}) raise UserInfoNotFound(extra_data={'error_docs': str(e)})
if user_dict:
result.update(user_dict) result.update(user_dict)
if body_info_dict: if body_info_dict:
result['height'] = body_info_dict.get('height', None) result['height'] = body_info_dict.get('height', None)