fix: update body record list api
continuous-integration/drone/push Build is passing Details

This commit is contained in:
BryantHe 2023-08-13 21:08:29 +08:00
parent 5ddf94aa82
commit 3a871e5c74
3 changed files with 10 additions and 4 deletions

View File

@ -37,7 +37,7 @@ def load_rpc_client(apiflask_app):
def create_app():
# http wsgi server 托管启动需指定读取环境配置
# load_dotenv(os.path.join(basedir, '.apiflaskenv'))
app = APIFlask(__name__)
app = APIFlask(__name__, title='Body Record API', version='1.0.0')
load_app_config(app)
register_blueprints(app)
load_rpc_client(app)

View File

@ -3,7 +3,7 @@ from flask import session
from app import rpc
from app.api.v1.exception.record import AddBodyRecordError, BodyRecordNotFound
from app.api.v1.schema.record import BodyRecordIn, BodyRecordOut, BodyRecordsOut
from app.api.v1.schema.record import BodyRecordIn, BodyRecordOut, BodyRecordsOut, BodyRecordsIn
from app.util.auth import login_required
record = APIBlueprint('record', __name__)
@ -40,11 +40,13 @@ def get_record(record_id):
@record.get('/list')
@record.doc(summary='查询身体记录列表', description='查询身体记录列表')
@record.input(BodyRecordsIn, location='query')
@record.output(BodyRecordsOut)
@login_required
def get_records():
def get_records(query_data):
try:
results = rpc.body_record.get_all_by_user(session['user_id'])
sort = query_data.get('sort', '-')
results = rpc.body_record.get_all_by_user(session['user_id'], sort)
except Exception as e:
raise BodyRecordNotFound()
return {'records': results}

View File

@ -17,5 +17,9 @@ class BodyRecordOut(Schema):
update_time = fields.String(allow_none=True)
class BodyRecordsIn(Schema):
sort = fields.String()
class BodyRecordsOut(Schema):
records = fields.List(fields.Nested(BodyRecordOut))