pzx-web-api/app/api/v1/interaction.py

41 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from apiflask import APIBlueprint
from flask import session
from app import rpc
from app.api.v1.exception.interaction import AddInteractionError
from app.api.v1.schema.interaction import InteractionIn, InteractionTodayIn, InteractionTodayOut
from app.util.auth import login_required
interaction = APIBlueprint('interaction', __name__)
@interaction.post('/')
@interaction.doc(summary='添加互动记录', description='添加互动记录category 类型int1:点赞2:加油3:评论')
@interaction.input(InteractionIn, location='json')
@login_required
def add_interaction(json_data):
try:
rpc.interaction.add(**{
'sender': session['user_id'],
'receiver': json_data['receiver_id'],
'category': json_data['category'],
'related_party': json_data.get('related_party_id'),
'comment': json_data.get('comment')
})
except Exception as e:
raise AddInteractionError(extra_data={'error_docs': str(e)})
return {'msg': 'add interaction successfully'}
@interaction.get('/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_interaction_brief(session['user_id'],
current_date=current_date)
return results