feat: add input field user id
continuous-integration/drone/push Build is passing Details

This commit is contained in:
BryantHe 2023-08-23 11:11:15 +08:00
parent 0ef80c8816
commit 1bb276939a
4 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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):

View File

@ -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()

View File

@ -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)})