fix: adjust api of add_interaction
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3b3365fcfb
commit
ca04e70d53
|
@ -6,6 +6,11 @@ class AddInteractionError(HTTPError):
|
|||
message = 'add interaction failed.'
|
||||
|
||||
|
||||
class InteractionExistedError(HTTPError):
|
||||
status_code = 401
|
||||
message = '已经提交过,不能再次提交~'
|
||||
|
||||
|
||||
class InteractionTodayBriefNotFound(HTTPError):
|
||||
status_code = 404
|
||||
message = '找不到用户对应的食物记录'
|
|
@ -2,7 +2,7 @@ from apiflask import APIBlueprint
|
|||
from flask import session
|
||||
|
||||
from app import rpc
|
||||
from app.api.v1.exception.interaction import AddInteractionError
|
||||
from app.api.v1.exception.interaction import AddInteractionError, InteractionExistedError
|
||||
from app.api.v1.schema.interaction import (InteractionIn, InteractionBriefIn, InteractionListIn,
|
||||
InteractionBriefOut, InteractionListOut)
|
||||
|
||||
|
@ -17,7 +17,7 @@ interaction = APIBlueprint('interaction', __name__)
|
|||
@login_required
|
||||
def add_interaction(json_data):
|
||||
try:
|
||||
rpc.interaction.add(**{
|
||||
is_existed = rpc.interaction.add(**{
|
||||
'sender': session['user_id'],
|
||||
'receiver': json_data['receiver_id'],
|
||||
'category': json_data['category'],
|
||||
|
@ -26,6 +26,8 @@ def add_interaction(json_data):
|
|||
})
|
||||
except Exception as e:
|
||||
raise AddInteractionError(extra_data={'error_docs': str(e)})
|
||||
if is_existed:
|
||||
raise InteractionExistedError()
|
||||
return {'msg': 'add interaction successfully'}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue