feat: 互动模块相关接口
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
73f6470559
commit
433cd7ca74
|
@ -5,6 +5,7 @@ from app.api.v1.auth import auth
|
||||||
from app.api.v1.record import record
|
from app.api.v1.record import record
|
||||||
from app.api.v1.user import user
|
from app.api.v1.user import user
|
||||||
from app.api.v1.diet import diet
|
from app.api.v1.diet import diet
|
||||||
|
from app.api.v1.interaction import interaction
|
||||||
|
|
||||||
|
|
||||||
def create_v1():
|
def create_v1():
|
||||||
|
@ -14,6 +15,7 @@ def create_v1():
|
||||||
bp_v1.register_blueprint(record, url_prefix='/record')
|
bp_v1.register_blueprint(record, url_prefix='/record')
|
||||||
bp_v1.register_blueprint(user, url_prefix='/user')
|
bp_v1.register_blueprint(user, url_prefix='/user')
|
||||||
bp_v1.register_blueprint(diet, url_prefix='/diet')
|
bp_v1.register_blueprint(diet, url_prefix='/diet')
|
||||||
|
bp_v1.register_blueprint(interaction, url_prefix='/interaction')
|
||||||
return bp_v1
|
return bp_v1
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
from apiflask import HTTPError
|
||||||
|
|
||||||
|
|
||||||
|
class AddInteractionError(HTTPError):
|
||||||
|
status_code = 500
|
||||||
|
message = 'add interaction failed.'
|
|
@ -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 类型int,1:点赞,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'}
|
|
@ -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)
|
Loading…
Reference in New Issue