diff --git a/app/__init__.py b/app/__init__.py index f72cdc5..a5f3c47 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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) diff --git a/app/api/v1/record.py b/app/api/v1/record.py index c783d38..2b4ebac 100644 --- a/app/api/v1/record.py +++ b/app/api/v1/record.py @@ -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} diff --git a/app/api/v1/schema/record.py b/app/api/v1/schema/record.py index 7260912..ccc2404 100644 --- a/app/api/v1/schema/record.py +++ b/app/api/v1/schema/record.py @@ -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)) \ No newline at end of file