diff --git a/app/api/v1/exception/interaction.py b/app/api/v1/exception/interaction.py index 2c7d8bd..2ddf25d 100644 --- a/app/api/v1/exception/interaction.py +++ b/app/api/v1/exception/interaction.py @@ -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 = '找不到用户对应的食物记录' \ No newline at end of file diff --git a/app/api/v1/interaction.py b/app/api/v1/interaction.py index b2d30ef..2673a09 100644 --- a/app/api/v1/interaction.py +++ b/app/api/v1/interaction.py @@ -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'}