feat: add api of body record 2
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c30c644f7c
commit
95621cf3fe
|
@ -10,6 +10,7 @@ auth = APIBlueprint('auth', __name__)
|
||||||
@auth.post('/wechat_login')
|
@auth.post('/wechat_login')
|
||||||
@auth.input(WechatLoginIn)
|
@auth.input(WechatLoginIn)
|
||||||
@auth.output(WechatLoginOut)
|
@auth.output(WechatLoginOut)
|
||||||
|
@auth.doc(summary='微信登录', description='微信登录', tags=['认证'])
|
||||||
def wechat_login(json_data):
|
def wechat_login(json_data):
|
||||||
try:
|
try:
|
||||||
result = rpc.admin.wechat_login(json_data['code'])
|
result = rpc.admin.wechat_login(json_data['code'])
|
||||||
|
@ -21,6 +22,7 @@ def wechat_login(json_data):
|
||||||
@auth.get('/refresh_token')
|
@auth.get('/refresh_token')
|
||||||
@auth.input(RefreshTokenIn, location='query')
|
@auth.input(RefreshTokenIn, location='query')
|
||||||
@auth.output(RefreshTokenOut)
|
@auth.output(RefreshTokenOut)
|
||||||
|
@auth.doc(summary='刷新 Token', description='刷新 Token', tags=['认证'])
|
||||||
def refresh_token(query_data):
|
def refresh_token(query_data):
|
||||||
try:
|
try:
|
||||||
result = rpc.admin.refresh_token(query_data['refresh_token'])
|
result = rpc.admin.refresh_token(query_data['refresh_token'])
|
||||||
|
|
|
@ -4,13 +4,14 @@ from flask import session
|
||||||
from app import rpc
|
from app import rpc
|
||||||
from app.api.v1.exception.record import AddBodyRecordError, BodyRecordNotFound
|
from app.api.v1.exception.record import AddBodyRecordError, BodyRecordNotFound
|
||||||
from app.api.v1.schema.record import BodyRecordIn, BodyRecordOut, BodyRecordsIn, BodyRecordsOut
|
from app.api.v1.schema.record import BodyRecordIn, BodyRecordOut, BodyRecordsIn, BodyRecordsOut
|
||||||
from app.util.common import login_required
|
from app.util.auth import login_required
|
||||||
|
|
||||||
record = APIBlueprint('record', __name__)
|
record = APIBlueprint('record', __name__)
|
||||||
|
|
||||||
|
|
||||||
@record.post('/')
|
@record.post('/')
|
||||||
@record.input(BodyRecordIn)
|
@record.input(BodyRecordIn)
|
||||||
|
@record.doc(summary='添加身体记录', description='添加身体记录', tags=['身体记录'])
|
||||||
@login_required
|
@login_required
|
||||||
def add_record(json_data):
|
def add_record(json_data):
|
||||||
try:
|
try:
|
||||||
|
@ -25,6 +26,7 @@ def add_record(json_data):
|
||||||
|
|
||||||
@record.get('/<record_id>')
|
@record.get('/<record_id>')
|
||||||
@record.output(BodyRecordOut)
|
@record.output(BodyRecordOut)
|
||||||
|
@record.doc(summary='查询单条身体记录', description='查询单条身体记录', tags=['身体记录'])
|
||||||
@login_required
|
@login_required
|
||||||
def get_record(record_id):
|
def get_record(record_id):
|
||||||
try:
|
try:
|
||||||
|
@ -37,8 +39,9 @@ def get_record(record_id):
|
||||||
@record.get('/list')
|
@record.get('/list')
|
||||||
@record.input(BodyRecordsIn, location='query')
|
@record.input(BodyRecordsIn, location='query')
|
||||||
@record.output(BodyRecordsOut)
|
@record.output(BodyRecordsOut)
|
||||||
|
@record.doc(summary='查询身体记录列表', description='查询身体记录列表', tags=['身体记录'])
|
||||||
@login_required
|
@login_required
|
||||||
def get_record(query_data):
|
def get_records(query_data):
|
||||||
try:
|
try:
|
||||||
result = rpc.body_record.get_all_by_user(query_data['user_id'])
|
result = rpc.body_record.get_all_by_user(query_data['user_id'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
from flask import request, session
|
||||||
|
|
||||||
|
from app.api.v1.exception.auth import AuthError
|
||||||
|
|
||||||
|
|
||||||
|
def login_required(f):
|
||||||
|
"""
|
||||||
|
登陆保护,验证用户是否登陆
|
||||||
|
"""
|
||||||
|
from app import rpc
|
||||||
|
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
token = request.headers.get("Authorization", default=None)
|
||||||
|
if not token:
|
||||||
|
raise AuthError()
|
||||||
|
user_id = rpc.admin.identify(token)
|
||||||
|
if not user_id:
|
||||||
|
raise AuthError()
|
||||||
|
session['user_id'] = user_id
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
|
@ -1,11 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from functools import wraps
|
|
||||||
|
|
||||||
from flask import request, session
|
|
||||||
|
|
||||||
from app.api.v1.exception.auth import AuthError
|
|
||||||
|
|
||||||
|
|
||||||
def split_group(dict_list, key):
|
def split_group(dict_list, key):
|
||||||
|
@ -20,20 +15,4 @@ def split_group(dict_list, key):
|
||||||
basedir = os.getcwd()
|
basedir = os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
def login_required(f):
|
|
||||||
"""
|
|
||||||
登陆保护,验证用户是否登陆
|
|
||||||
"""
|
|
||||||
from app import rpc
|
|
||||||
|
|
||||||
@wraps(f)
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
token = request.headers.get("Authorization", default=None)
|
|
||||||
if not token:
|
|
||||||
raise AuthError()
|
|
||||||
user_id = rpc.admin.identify(token)
|
|
||||||
if not user_id:
|
|
||||||
raise AuthError()
|
|
||||||
session['user_id'] = user_id
|
|
||||||
return f(*args, **kwargs)
|
|
||||||
return wrapper
|
|
||||||
|
|
Loading…
Reference in New Issue