Skip to content

Commit

Permalink
Return flag to indicate user reacted to a page or not
Browse files Browse the repository at this point in the history
  • Loading branch information
smanga24 committed Jan 22, 2025
1 parent cfc9b4b commit 436f1ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/interactions/services/reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ def get_user_reaction(user: User, page: Page) -> ReactionType | None:
if reaction:
return reaction.type
return None


def has_user_reacted(user: User, page: Page) -> bool:
return Reaction.objects.filter(user=user, page=page).exists()
11 changes: 11 additions & 0 deletions src/interactions/test/services/test_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get_reaction_count,
get_reaction_counts,
get_user_reaction,
has_user_reacted,
)

ALL_REACTION_TYPES = ReactionType.values
Expand Down Expand Up @@ -111,3 +112,13 @@ def test_get_user_reaction(user, news_page, create_reaction):
@pytest.mark.django_db
def test_get_user_reaction_no_page_found(user, news_page):
assert get_user_reaction(user, news_page) is None


@pytest.mark.django_db
def test_has_user_not_reacted(user, news_page):
assert has_user_reacted(user, news_page) is False


@pytest.mark.django_db
def test_has_user_reacted(user, news_page, create_reaction):
assert has_user_reacted(user, news_page) is True

0 comments on commit 436f1ca

Please sign in to comment.