From 70589a35da6263169a754076f0aea53403eb6993 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 6 Mar 2024 12:15:26 +0300 Subject: [PATCH] cosmetics --- resolvers/reaction.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/resolvers/reaction.py b/resolvers/reaction.py index b3042909..7c3bb8de 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -148,7 +148,7 @@ async def _create_reaction(session, shout, author, reaction): return rdict -def check_rating(reaction: dict, shout_id: int, session, author: Author): +def prepare_new_rating(reaction: dict, shout_id: int, session, author: Author): kind = reaction.get('kind') opposite_kind = ( ReactionKind.DISLIKE.value if is_positive(kind) else ReactionKind.LIKE.value @@ -208,11 +208,14 @@ async def create_reaction(_, info, reaction): return {'error': 'cannot create reaction without a kind'} if kind in RATING_REACTIONS: - result = check_rating(reaction, shout_id, session, author) - if result: - return result + error_result = prepare_new_rating(reaction, shout_id, session, author) + if error_result: + return error_result rdict = await _create_reaction(session, shout, author, reaction) + + # TODO: call recount ratings periodically + return {'reaction': rdict} except Exception as e: import traceback