pzx-web-api/app/api/v1/user.py

55 lines
1.7 KiB
Python
Raw Normal View History

2023-08-15 17:49:05 +08:00
from apiflask import APIBlueprint
from flask import session
from app import rpc
from app.api.v1.exception.user import UserInfoNotFound, UserInfoError
from app.api.v1.schema.user import UserInfoIn, UserInfoOut
from app.util.auth import login_required
user = APIBlueprint('user', __name__)
@user.post('/info')
@user.doc(summary='设置用户信息', description='设置用户信息')
@user.input(UserInfoIn, location='json')
@login_required
def wechat_login(json_data):
try:
rpc.admin.set_user_info(session['user_id'],
json_data.get('nickname'),
json_data.get('avatar_url'))
except Exception as e:
raise UserInfoError(extra_data={'error_docs': str(e)})
try:
rpc.body_record.set_body_info(session['user_id'],
height=json_data.get('height'))
except Exception as e:
raise UserInfoError(extra_data={'error_docs': str(e)})
return {'msg': 'setting user info success'}
@user.get('/info')
@user.doc(summary='查询用户信息', description='查询用户信息')
@user.output(UserInfoOut)
@login_required
def refresh_token():
result = {}
try:
user_dict = rpc.admin.get_user_info(session['user_id'])
except Exception as e:
raise UserInfoNotFound(extra_data={'error_docs': str(e)})
try:
body_info_dict = rpc.body_record.get_body_info(session['user_id'])
except Exception as e:
raise UserInfoNotFound(extra_data={'error_docs': str(e)})
if user_dict:
result.update(user_dict)
if body_info_dict:
user_dict['height'] = body_info_dict['height']
return result