-
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
base: dev
Are you sure you want to change the base?
Conversation
Specifies how user data should be serialized
added UserCreateView to allow for the POST of users
added a view to deal with creating a new User
Added a check for authenticated users only to be able to send GET, POST, and PATCH requests for User info.
As of right now, the POST endpoint for "sending invitations" and the GET endpoint for the LISTview of invitations are working. There is an issue with accepting invitations that stems from the model itself (accept_invitation method is not working properly) |
The Accept Invite POST Endpoint works now, meaning that all three endpoints are successful. I also had to make endpoints for the UserProfile objects since it is a separate model from Users. I introduced three endpoints for this, each handling POST, PATCH, and GET (listview) requests. This had to be done to ensure that the Friend Invitation endpoint functioned properly. |
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.
Looks good!
…cago-cs/chigame into apis/create-friend-requests
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.
This is looking better now! There are more places to polish up.
Immediate problem is that, with the current version of the code, upon trying to access the sending enpoint, I get an error message which asks me to add fields = "__all__" to the
UserProfileSerializer`.
After doing so locally, I could get from http://localhost:8000/api/friend-invitations/
the list. In each entry seeing the id
accepted
status, timestamp
, sender
, and receiver
:
I was then able to navigate to multiple different
http://localhost:8000/api/friend-invitations/send/<sender pk>/<receiver pk>
endpoints.
then upon sending an empty post request (via just clicking post on an empty message via the DRF gui:
I get feedback that my POST is successful
Then if I give user primary keys that are invalid, I am returned an unsuccessful response to my POST request:
I can then go to: http://localhost:8000/api/friend-invitations/ and see a lit of all the POST'ed friend invitation
{
"id": 14,
"accepted": false,
"timestamp": "2023-12-07T16:49:39.098944-06:00",
"sender": 1,
"receiver": 2
},
{
"id": 15,
"accepted": false,
"timestamp": "2023-12-07T16:49:43.343774-06:00",
"sender": 1,
"receiver": 3
},
{
"id": 16,
"accepted": false,
"timestamp": "2023-12-07T16:49:47.416511-06:00",
"sender": 1,
"receiver": 4
},
{
"id": 17,
"accepted": false,
"timestamp": "2023-12-07T16:49:55.486581-06:00",
"sender": 2,
"receiver": 3
},
{
"id": 18,
"accepted": false,
"timestamp": "2023-12-07T16:52:01.030614-06:00",
"sender": 2,
"receiver": 7
}
However, there is a problem here
Once I try to accept an invitation by POST'ing at the friend-invitation/accept
endpoint (such as at URL: http://localhost:8000/api/friend-invitations/accept/18/ ) I get the following error:
Then there also seems to be some JWT user authentication code still in this PR
Overall, please:
[] add the fields = "__all__" to the
UserProfileSerializer`
[] update your code and test if accepting inivtations actually works
[] remove the extraneuous code as it's been commented upon
[] generally answer all comments
permission_classes = [IsAuthenticated] | ||
|
||
|
||
class UserProfileUpdateView(APIView): |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I am removing the permission classes
serializer_class = FriendInvitationSerializer | ||
|
||
|
||
class UserProfileCreateView(APIView): |
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
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.
Even after creating user profiles through the administrator site, I am still not able to actually accept friend invitations.
I specifically created 4 user profiles via the admin
page:
Then I made have a request with pk=1
from profile id=1 to profile id=2:
Thus to my understand of how your endpoints are supposed to work, I should then be able to go to:
http://localhost:8000/api/friend-invitations/accept/1/
which corresponds to friend invitation pk=1
Then by posting nothing to this endpoint, it should then cause this friend invitation to be accepted, in my example making profiles 1 and 2 friends.
However when I post with the following:
Which upon further inspection, happens in the .accept_invitation()
call on line 134:
invitation.accept_invitation() # Error with this method in the users.models
Where in my case, it is failing when trying to run the line:
receiver_profile = UserProfile.objects.get(user__pk=receiver.pk)
where the reciever.pk
We can create a bugfix issue to ask the users team to look at this method, since we don't think it should be failing.is 2.
Also, unless I need to create UserProfiles through the API endpoint specifically instead of the admin site, I don't understand what the problem is.
We can create a bugfix issue to ask the users team to look at this method, since we don't think it should be failing.
For now, if I've properly understood how these endpoints are supposed to work, your coded functionality fails due to a function outside of your team.
Overall, this is the current state of trying to run this code, please do the following:
- if you want, try to see if the reason I can't accept friend invitations is because of something in your code
- make a bugfix issue for the users team which details AND LINKS TO what's going wrong in this PR with
accept_invitation()
Creating two separate API endpoints that deal with POST requests for Friend Invitations. To send an invitation, a Friend Invitation object is posted at URL
friend-invitations/send/sender<pk>/receiver<pk>/
and to accept, the endpoint is run at:
friend-invitations/accept/invite<pk>/
Then a third endpoint that deals with a GET request for a ListView of all Friend Invitations (pending and accepted) is created at:
/friend-invitations/