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

CRUD APIs for Locations model #75

Merged
merged 23 commits into from
Nov 18, 2023
Merged

CRUD APIs for Locations model #75

merged 23 commits into from
Nov 18, 2023

Conversation

ManaliTanna
Copy link
Contributor

Added code for the locations API

POST - Inserts a new location record for the logged in user (see image 1), it returns the location_id of the newly created record in the DB

image 1

GET - It fetches all the locations for the logged in user (see image 2)

image 2

PUT/PATCH - It takes as input location id and location details to update and returns the updated record (see image 3)

image 3

DELETE - Deletes the record for the given location id (see image 4)

image 4

@ManaliTanna ManaliTanna self-assigned this Nov 3, 2023
Copy link

vercel bot commented Nov 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
inet-monday-fall2023-team-1 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2023 10:23pm

Copy link
Contributor

@kolharsam kolharsam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look into the review comments with a pinch of salt and also make sure merge develop branch into this branch so that current conflicts could be resolved.

If you have any questions or any other comments regarding my suggestions, please feel free to discuss them here or any other place.

You could also ignore some comments that you think are not important at the moment but be sure to comment that you are ignoring it with a reason.

Great work, thank you! :)

.env Outdated Show resolved Hide resolved
furbaby/api/serializers.py Show resolved Hide resolved
furbaby/api/views.py Outdated Show resolved Hide resolved
furbaby/api/views.py Outdated Show resolved Hide resolved
furbaby/api/views.py Outdated Show resolved Hide resolved
Comment on lines 262 to 265
locations = Locations.objects.filter(user_id=user_id)
serialized_data = serialize("json", locations)
serialized_data = json.loads(serialized_data)
return serialized_data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try something else with this? I see that the response is still a JSON string instead of it being a JSON array
I'd really appreciate it if you could spend a little bit more time on this and get a better way of providing the response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a list (ie array) of dictionaries containing the locations. Is that an acceptable format for the response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this works for now, I mean...we're not going to be dealing with 1000s of objects where performance of the API is affected at the moment. But in the meanwhile, if we do find something that can work...we should definitely come back to this and replace it! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

furbaby/api/views.py Outdated Show resolved Hide resolved
furbaby/api/views.py Outdated Show resolved Hide resolved
furbaby/api/views.py Show resolved Hide resolved
@kolharsam kolharsam changed the title Manali/locations api CRUD APIs for Locations model Nov 6, 2023
Copy link
Contributor

@kolharsam kolharsam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks great! Congratulations on following through completely with your first PR!🎉

Thanks for your efforts, I appreciate it! :)

Work on the changes based on my latest comments if you'd like to and merge if you think you're ready!

furbaby/api/views.py Outdated Show resolved Hide resolved
furbaby/api/views.py Show resolved Hide resolved
Comment on lines +306 to +314
except Locations.DoesNotExist:
return json_response(
data={
"error": "location not found for user",
"location id": location_id,
"user id": request.user.id,
},
status=status.HTTP_404_NOT_FOUND,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-pick:

what you've done here is completely fine, but I was thinking that if we're going to check it every time, it can become a little redundant. What do you think of making it one common test in the main handler and we assume that the location is always present when you're in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we take this up in the next PR?

@kolharsam
Copy link
Contributor

kolharsam commented Nov 6, 2023

Don't merge this yet please, there's an issue with Travis CI and so deployments won't go through. Just hold on until that has been figured out?

You can see the error coming up here: https://app.travis-ci.com/github/gcivil-nyu-org/INET-Monday-Fall2023-Team-1?serverType=git

image

@ManaliTanna ManaliTanna merged commit faed5da into develop Nov 18, 2023
4 checks passed
ManaliTanna added a commit that referenced this pull request Nov 18, 2023
Added code for the locations API

POST - Inserts a new location record for the logged in user (see image
1), it returns the location_id of the newly created record in the DB

<img width="902" alt="image 1"
src="https://github.com/gcivil-nyu-org/INET-Monday-Fall2023-Team-1/assets/57152208/698d5cab-370e-469e-b64f-50824951750a">

GET - It fetches all the locations for the logged in user (see image 2)

<img width="1083" alt="image 2"
src="https://github.com/gcivil-nyu-org/INET-Monday-Fall2023-Team-1/assets/57152208/1798a0f0-1165-428b-abbe-8fc4cf942c10">

PUT/PATCH - It takes as input location id and location details to update
and returns the updated record (see image 3)

<img width="1081" alt="image 3"
src="https://github.com/gcivil-nyu-org/INET-Monday-Fall2023-Team-1/assets/57152208/cc4d4b12-9136-4a59-b2ce-4b81dd824663">

DELETE - Deletes the record for the given location id (see image 4)

<img width="1079" alt="image 4"
src="https://github.com/gcivil-nyu-org/INET-Monday-Fall2023-Team-1/assets/57152208/89b02640-e36a-4d91-903d-eb080bdca8bc">
@kolharsam kolharsam deleted the manali/locations-api branch December 10, 2023 05:03
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

Successfully merging this pull request may close these issues.

2 participants