Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add util method within FriendshipManager to check if friend request is sent #198

Open
Azeddev28 opened this issue Aug 26, 2024 · 3 comments

Comments

@Azeddev28
Copy link

Azeddev28 commented Aug 26, 2024

Within FrienshipManager, there are two checks:

if FriendshipRequest.objects.filter(
from_user=from_user, to_user=to_user
).exists():
raise AlreadyExistsError("You already requested friendship from this user.")
if FriendshipRequest.objects.filter(
from_user=to_user, to_user=from_user
).exists():
raise AlreadyExistsError("This user already requested friendship from you.")

These validate if a request is sent from a from_user or a to_user. These can be converted into a util method to be used from the FrienshipManager rather than copying these two checks outside of the manager if needed.

I have the util method defined like this

  def check_if_request_sent(self, from_user, to_user):
        if FriendshipRequest.objects.filter(
            from_user=from_user, to_user=to_user
        ).exists():
            raise AlreadyExistsError("You already requested friendship from this user.")

        if FriendshipRequest.objects.filter(
            from_user=to_user, to_user=from_user
        ).exists():
            raise AlreadyExistsError("This user already requested friendship from you.")

Can open a PR, once the idea is approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@Azeddev28 and others