diff --git a/app/api/v1/record.py b/app/api/v1/record.py index 810bd70..e65dcea 100644 --- a/app/api/v1/record.py +++ b/app/api/v1/record.py @@ -59,10 +59,11 @@ def get_records(query_data): @record.output(BodyRecordChartOut) @login_required def get_record_charts(query_data): + user_id = query_data['user_id'] if query_data.get('user_id') else session['user_id'] try: period = query_data.get('period', 'week') current_date = query_data['current_date'] - result = rpc.body_record.get_record_charts(session['user_id'], current_date, period) + result = rpc.body_record.get_record_charts(user_id, current_date, period) except Exception as e: raise BodyRecordChartError(extra_data={'error_docs': str(e)}) return result diff --git a/app/api/v1/schema/record.py b/app/api/v1/schema/record.py index f8634f5..cd01560 100644 --- a/app/api/v1/schema/record.py +++ b/app/api/v1/schema/record.py @@ -28,6 +28,7 @@ class BodyRecordsOut(Schema): class BodyRecordChartIn(Schema): current_date = fields.String(required=True) period = fields.String() + user_id = fields.String() class BodyRecordChartNestedOut(Schema): diff --git a/app/api/v1/schema/user.py b/app/api/v1/schema/user.py index ad0770d..b83a886 100644 --- a/app/api/v1/schema/user.py +++ b/app/api/v1/schema/user.py @@ -8,6 +8,10 @@ class UserInfoIn(Schema): is_hidden_weight = Boolean() +class UserIdIn(Schema): + user_id = String() + + class UserInfoOut(Schema): user_id = String(attribute='_id') nickname = String() diff --git a/app/api/v1/user.py b/app/api/v1/user.py index 232dddf..fe24592 100644 --- a/app/api/v1/user.py +++ b/app/api/v1/user.py @@ -4,7 +4,7 @@ from flask import session 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.schema.user import UserInfoIn, UserInfoOut +from app.api.v1.schema.user import UserInfoIn, UserInfoOut, UserIdIn from app.util.auth import login_required user = APIBlueprint('user', __name__) @@ -33,12 +33,14 @@ def set_user_info(json_data): @user.get('/info') @user.doc(summary='查询用户信息', description='查询用户信息') +@user.input(UserIdIn, location='query') @user.output(UserInfoOut) @login_required -def get_user_info(): +def get_user_info(query_data): + user_id = query_data['user_id'] if query_data.get('user_id') else session['user_id'] result = {} try: - user_dict = rpc.admin.get_user_info(session['user_id']) + user_dict = rpc.admin.get_user_info(user_id) except Exception as e: raise UserInfoNotFound(extra_data={'error_docs': str(e)}) @@ -51,7 +53,7 @@ def get_user_info(): raise ImageNotFound(extra_data={'error_docs': str(e)}) try: - body_info_dict = rpc.body_record.get_body_info(session['user_id']) + body_info_dict = rpc.body_record.get_body_info(user_id) except Exception as e: raise UserInfoNotFound(extra_data={'error_docs': str(e)})