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

57 lines
2.3 KiB
Python
Raw Normal View History

2023-09-18 16:29:24 +08:00
from apiflask import APIBlueprint
from flask import session
from app import rpc
2023-09-21 15:01:16 +08:00
from app.api.v1.exception.interaction import AddInteractionError
2023-09-20 11:59:51 +08:00
from app.api.v1.schema.interaction import (InteractionIn, InteractionBriefIn, InteractionListIn,
InteractionBriefOut, InteractionListOut)
2023-09-18 16:29:24 +08:00
from app.util.auth import login_required
interaction = APIBlueprint('interaction', __name__)
@interaction.post('/')
2023-09-18 16:52:26 +08:00
@interaction.doc(summary='添加互动记录', description='添加互动记录category 类型int1:点赞2:加油3:评论')
2023-09-18 16:29:24 +08:00
@interaction.input(InteractionIn, location='json')
@login_required
def add_interaction(json_data):
try:
2023-09-21 14:53:37 +08:00
is_existed = rpc.interaction.add(**{
2023-09-18 16:29:24 +08:00
'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)})
2023-09-21 14:53:37 +08:00
if is_existed:
2023-09-21 15:02:29 +08:00
return {'msg': '不能重复提交了~', 'code': 401}
2023-09-21 15:01:16 +08:00
return {'msg': 'add interaction successfully', 'code': 200}
2023-09-19 17:15:07 +08:00
2023-09-19 17:34:43 +08:00
@interaction.get('/brief')
2023-09-20 11:59:51 +08:00
@interaction.doc(summary='查询互动简要数据', description='查询互动简要数据')
@interaction.input(InteractionBriefIn, location='query')
@interaction.output(InteractionBriefOut)
2023-09-19 17:15:07 +08:00
@login_required
2023-09-20 11:59:51 +08:00
def get_interaction_brief(query_data):
2023-09-19 17:15:07 +08:00
current_date = query_data.get('current_date', None)
2023-09-19 17:34:43 +08:00
results = rpc.interaction.get_interaction_brief(session['user_id'],
current_date=current_date)
return results
2023-09-20 11:59:51 +08:00
@interaction.get('/list')
@interaction.doc(summary='查询互动列表数据', description='查询互动列表数据')
@interaction.input(InteractionListIn, location='query')
@interaction.output(InteractionListOut)
@login_required
def get_interaction_list(query_data):
current_date = query_data.get('current_date', None)
results = rpc.interaction.get_interaction_list(session['user_id'],
category=query_data['category'],
current_date=current_date)
return {'interactions': results}