feat: add api of today brief
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
BryantHe 2023-09-19 17:15:07 +08:00
parent 7f21fac864
commit 4214e7b797
3 changed files with 31 additions and 4 deletions

View File

@ -3,4 +3,9 @@ from apiflask import HTTPError
class AddInteractionError(HTTPError): class AddInteractionError(HTTPError):
status_code = 500 status_code = 500
message = 'add interaction failed.' message = 'add interaction failed.'
class InteractionTodayBriefNotFound(HTTPError):
status_code = 404
message = '找不到用户对应的食物记录'

View File

@ -3,7 +3,7 @@ from flask import session
from app import rpc from app import rpc
from app.api.v1.exception.interaction import AddInteractionError from app.api.v1.exception.interaction import AddInteractionError
from app.api.v1.schema.interaction import InteractionIn from app.api.v1.schema.interaction import InteractionIn, InteractionTodayIn, InteractionTodayOut
from app.util.auth import login_required from app.util.auth import login_required
@ -25,4 +25,16 @@ def add_interaction(json_data):
}) })
except Exception as e: except Exception as e:
raise AddInteractionError(extra_data={'error_docs': str(e)}) raise AddInteractionError(extra_data={'error_docs': str(e)})
return {'msg': 'add interaction successfully'} return {'msg': 'add interaction successfully'}
@interaction.get('/today/brief')
@interaction.doc(summary='查询食物记录列表', description='查询食物记录列表')
@interaction.input(InteractionTodayIn, location='query')
@interaction.output(InteractionTodayOut)
@login_required
def get_interaction_today_brief(query_data):
current_date = query_data.get('current_date', None)
results = rpc.interaction.get_today_brief(session['user_id'],
current_date=current_date)
return results

View File

@ -6,4 +6,14 @@ class InteractionIn(Schema):
category = fields.Integer() category = fields.Integer()
receiver_id = fields.String() receiver_id = fields.String()
related_party_id = fields.String(allow_none=True) related_party_id = fields.String(allow_none=True)
comment = fields.String(allow_none=True) comment = fields.String(allow_none=True)
class InteractionTodayIn(Schema):
current_date = fields.String()
class InteractionTodayOut(Schema):
fire_count = fields.Integer()
heart_count = fields.Integer()
comment_count = fields.Integer()