Skip to content

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

@Azeddev28

Description

@Azeddev28

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions