-
Notifications
You must be signed in to change notification settings - Fork 0
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
POST API Endpoints for Sending and Accepting Friend invitations between two Users; GET request endpoint for listview for Friend Invites #370
Open
Esterello2
wants to merge
37
commits into
dev
Choose a base branch
from
apis/create-friend-requests
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
90d71a7
Create serializers.py
Esterello2 d9792c7
Update urls.py
Esterello2 fd712df
Update views.py
Esterello2 734d40d
Update views.py
Esterello2 e48159f
Update
Esterello2 f3bc490
Deleted some files
Esterello2 7ec1924
Merge branch 'dev' of https://github.com/uchicago-cs/chigame into api…
Esterello2 6525622
Fixed CI error
Esterello2 ed8943a
Merge branch 'dev' into apis/post-users
Esterello2 d4d41c1
Fixing CI issues
Esterello2 23ae6ea
fixing CI issue in urls.py
Esterello2 b04b0fa
Fixing CI issues
Esterello2 6ee326c
Fixing CI
Esterello2 8be6de9
Fix CI
Esterello2 d05711d
CI ISsue
Esterello2 2a5fa11
Fixing CI
Esterello2 2759d2a
sd
Esterello2 554e5e8
djsdf
Esterello2 f17eda4
update:
Esterello2 8a2f865
Merge branch 'dev' into apis/post-users
Esterello2 4deeba5
update
Esterello2 86aad2a
Fixing CI
Esterello2 e2bb59c
Merge branch 'dev' into apis/create-friend-requests
abrahmasandra e355d91
Adjustments
Esterello2 f2e7ef4
update
Esterello2 a845ea4
Merge branch 'dev' into apis/create-friend-requests
Esterello2 8e8dbeb
Merge branch 'apis/create-friend-requests' of https://github.com/uchi…
Esterello2 888ac68
Merge branch 'dev' into apis/create-friend-requests
majorsylvie a472162
update
Esterello2 e46b2d5
Merge branch 'dev' into apis/create-friend-requests
Esterello2 a50ea82
lint
Esterello2 615d142
Merge branch 'dev' into apis/create-friend-requests
Esterello2 28cad16
update
Esterello2 23e62f8
deleting extra code
Esterello2 c804cfa
updatre
Esterello2 9506857
update
Esterello2 b4ca844
Merge branch 'dev' into apis/create-friend-requests
majorsylvie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rest_framework.permissions import BasePermission | ||
|
||
|
||
class IsUnauthenticated(BasePermission): | ||
def has_permission(self, request, view): | ||
return not request.user or not request.user.is_authenticated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,20 @@ | |
from chigame.api.filters import GameFilter | ||
from chigame.api.serializers import ( | ||
CategorySerializer, | ||
FriendInvitationSerializer, | ||
GameSerializer, | ||
GroupSerializer, | ||
LobbySerializer, | ||
MechanicSerializer, | ||
MessageFeedSerializer, | ||
MessageSerializer, | ||
UserProfileSerializer, | ||
UserSerializer, | ||
) | ||
from chigame.games.models import Game, Lobby, Message, User | ||
from chigame.users.models import Group, UserProfile | ||
from chigame.games.models import Game, Lobby, Message | ||
from chigame.users.models import FriendInvitation, Group, User, UserProfile | ||
|
||
|
||
# Helper function to get user from slug | ||
def get_user(lookup_value): | ||
# If the lookup_value is an integer, use the id field | ||
if lookup_value.isdigit(): | ||
|
@@ -106,6 +107,73 @@ class MessageView(generics.CreateAPIView): | |
serializer_class = MessageSerializer | ||
|
||
|
||
class SendFriendInvitationView(APIView): | ||
def post(self, request, *args, **kwargs): | ||
sender_pk = self.kwargs["sender_pk"] | ||
receiver_pk = self.kwargs["receiver_pk"] | ||
sender = get_object_or_404(User, pk=sender_pk) | ||
receiver = get_object_or_404(User, pk=receiver_pk) | ||
if sender == receiver: | ||
return Response( | ||
{"detail": "You cannot send an invitation to yourself."}, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
invitation = FriendInvitation(sender=sender, receiver=receiver) | ||
invitation.save() | ||
serializer = FriendInvitationSerializer(invitation) | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
|
||
class AcceptFriendInvitationView(APIView): | ||
def post(self, request, *args, **kwargs): | ||
invitation_pk = self.kwargs["invitation_pk"] | ||
invitation = get_object_or_404(FriendInvitation, pk=invitation_pk) | ||
if invitation.accepted: | ||
return Response( | ||
{"detail": "This invitation has already been accepted."}, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
invitation.accept_invitation() # Error with this method in the users.models | ||
serializer = FriendInvitationSerializer(invitation) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
|
||
class FriendInvitationList(generics.ListAPIView): | ||
queryset = FriendInvitation.objects.all() | ||
serializer_class = FriendInvitationSerializer | ||
|
||
|
||
class UserProfileCreateView(APIView): | ||
def post(self, request, *args, **kwargs): | ||
user_pk = self.kwargs["user_pk"] | ||
user = get_object_or_404(User, pk=user_pk) | ||
existing_profile = UserProfile.objects.filter(user=user).first() | ||
if existing_profile: | ||
serializer = UserProfileSerializer(existing_profile) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
serializer = UserProfileSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
profile = serializer.save(user=user) | ||
return Response(UserProfileSerializer(profile).data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
class UserProfileListView(generics.ListAPIView): | ||
queryset = UserProfile.objects.all() | ||
serializer_class = UserProfileSerializer | ||
|
||
|
||
class UserProfileUpdateView(APIView): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both this update and user profile list view are relevant for JWT and are related to authentication. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I am removing the permission classes |
||
def patch(self, request, *args, **kwargs): | ||
user_profile_pk = self.kwargs["user_profile_pk"] | ||
user_profile = get_object_or_404(UserProfile, pk=user_profile_pk) | ||
|
||
serializer = UserProfileSerializer(user_profile, data=request.data, partial=True) | ||
if serializer.is_valid(): | ||
updated_profile = serializer.save() | ||
return Response(UserProfileSerializer(updated_profile).data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
class GroupListView(generics.ListCreateAPIView): | ||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ | |
"django_filters", | ||
"django_tables2", | ||
] | ||
|
||
THIRD_PARTY_APPS = [ | ||
"crispy_forms", | ||
"crispy_bootstrap5", | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this class have to do with friend invitations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IT is because Friend Invitations use User Profile pks rather than User class, so I had to create a way to make these UserProfile objects