feat: add api of body record chart
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a21bd3aef5
commit
a55e4b97d6
|
@ -8,4 +8,9 @@ class AddBodyRecordError(HTTPError):
|
|||
|
||||
class BodyRecordNotFound(HTTPError):
|
||||
status_code = 404
|
||||
message = '找不到该记录'
|
||||
message = '找不到该记录'
|
||||
|
||||
|
||||
class BodyRecordChartError(HTTPError):
|
||||
status_code = 500
|
||||
message = '查询身体记录图表错误'
|
|
@ -2,8 +2,9 @@ from apiflask import APIBlueprint
|
|||
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, BodyRecordsIn
|
||||
from app.api.v1.exception.record import AddBodyRecordError, BodyRecordNotFound, BodyRecordChartError
|
||||
from app.api.v1.schema.record import BodyRecordIn, BodyRecordOut, BodyRecordsOut, BodyRecordsIn, BodyRecordChartIn, \
|
||||
BodyRecordChartOut
|
||||
from app.util.auth import login_required
|
||||
|
||||
record = APIBlueprint('record', __name__)
|
||||
|
@ -50,3 +51,18 @@ def get_records(query_data):
|
|||
except Exception as e:
|
||||
raise BodyRecordNotFound(extra_data={'error_docs': str(e)})
|
||||
return {'records': results}
|
||||
|
||||
|
||||
@record.get('/chart')
|
||||
@record.doc(summary='查询身体记录图表', description='查询身体记录图表')
|
||||
@record.input(BodyRecordChartIn, location='query')
|
||||
@record.output(BodyRecordChartOut)
|
||||
@login_required
|
||||
def get_record_charts(query_data):
|
||||
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)
|
||||
except Exception as e:
|
||||
raise BodyRecordChartError(extra_data={'error_docs': str(e)})
|
||||
return result
|
||||
|
|
|
@ -22,4 +22,21 @@ class BodyRecordsIn(Schema):
|
|||
|
||||
|
||||
class BodyRecordsOut(Schema):
|
||||
records = fields.List(fields.Nested(BodyRecordOut))
|
||||
records = fields.List(fields.Nested(BodyRecordOut))
|
||||
|
||||
|
||||
class BodyRecordChartIn(Schema):
|
||||
current_date = fields.String(required=True)
|
||||
period = fields.String()
|
||||
|
||||
|
||||
class BodyRecordChartNestedOut(Schema):
|
||||
weights = fields.List(fields.Float())
|
||||
bmis = fields.List(fields.Float())
|
||||
x_axis = fields.List(fields.Float())
|
||||
|
||||
|
||||
class BodyRecordChartOut(Schema):
|
||||
chart_data = fields.Nested(BodyRecordChartNestedOut)
|
||||
previous_date = fields.String()
|
||||
next_date = fields.String()
|
||||
|
|
Loading…
Reference in New Issue