feat: 互动模块相关接口
continuous-integration/drone/push Build is passing Details

This commit is contained in:
BryantHe 2023-09-18 16:29:24 +08:00
parent 73f6470559
commit 433cd7ca74
4 changed files with 45 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from app.api.v1.auth import auth
from app.api.v1.record import record
from app.api.v1.user import user
from app.api.v1.diet import diet
from app.api.v1.interaction import interaction
def create_v1():
@ -14,6 +15,7 @@ def create_v1():
bp_v1.register_blueprint(record, url_prefix='/record')
bp_v1.register_blueprint(user, url_prefix='/user')
bp_v1.register_blueprint(diet, url_prefix='/diet')
bp_v1.register_blueprint(interaction, url_prefix='/interaction')
return bp_v1

View File

@ -0,0 +1,6 @@
from apiflask import HTTPError
class AddInteractionError(HTTPError):
status_code = 500
message = 'add interaction failed.'

28
app/api/v1/interaction.py Normal file
View File

@ -0,0 +1,28 @@
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
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'}

View File

@ -0,0 +1,9 @@
from apiflask import Schema
from apiflask import fields
class InteractionIn(Schema):
category = fields.Integer()
receiver_id = fields.String()
related_party_id = fields.String(allow_none=True)
comment = fields.String(allow_none=True)