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

Endpoint users/ GET method #356

Merged
merged 2 commits into from
Sep 8, 2019
Merged

Endpoint users/ GET method #356

merged 2 commits into from
Sep 8, 2019

Conversation

wittejm
Copy link
Contributor

@wittejm wittejm commented Sep 4, 2019

This is a backend API call to get the list of users currently in the database.
The new code includes the necessary db operations, the endpoint, test cases, and the design spec added to our design.md document.

This endpoint is needed for completing the frontend Users component, issue #91



**`GET`** `/api/users/EMAIL`

Copy link
Contributor

Choose a reason for hiding this comment

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

Using the user's email address as the unique identifier for lookup in a URL feels weird (as a login name it's fine). I'd rather see a user id or username here. Not adamantly opposed, just want to discuss it before it's implemented

Copy link
Contributor Author

@wittejm wittejm Sep 5, 2019

Choose a reason for hiding this comment

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

Yea, I agree it's weird and think it's worth revisiting. This particular endpoint isn't implemented in this PR.

...I think we'll need to check in on the end-to-end design to decide when/how we fetch just one user's info

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @erikjasso as I'm not opposed to it, but I believe its common practice to use a user id for this action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In our spec, email is the only public-facing identifier for a user because we eliminated the "username" field, deciding it was functionally redundant with just using an email address, and the user_id field is a UUID generated by the database.

I can pull this design question into a new issue since it's not in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I have seen this done as an /api/users/search as a post where you send the required information along in the request ie: Email. That way you don't have to expose the UUID to the front end.

I agree that it could be beneficial to spec out naming conventions and requisite data for the endpoints at our next meeting.

@@ -51,5 +51,24 @@ def post(self):

return jsonify(response_data), 201

@admin_auth_required
def get(self):
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can name this index as it is indexing all users? I think the name get is very generic as it could refer to get_users, get_user, get_user_new, or get_user_edit?

Copy link
Contributor Author

@wittejm wittejm Sep 5, 2019

Choose a reason for hiding this comment

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

This function is called get because it's the GET http request of the /api/users/ endpoint, and the MethodView class in Flask for defining endpoints needs to use the same name.

I agree it's all a little too generic and needs redesign. I think the present users.GET to get all users seems fine but users.POST to create a new user is confusing. And the GET for a single user needs to be different. This deserves its own issue to hash out a naming scheme.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Should we write down all of our endpoints (URI's), and document how they're going to be routed so that we can use some naming conventions that imply intent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, lets.


for (email, hashed_password, admin) in [
(r['email'], r['hashed_password'], r['admin']) for r in users_get_endpoint_result]:
self.verify_user_data(email, hashed_password, admin)
Copy link
Member

Choose a reason for hiding this comment

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

What is this for loop for after the assert statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It manually checks that the entire returned set of entries from the endpoint match what's in the db.

@wittejm
Copy link
Contributor Author

wittejm commented Sep 8, 2019

Merging this. this GET endpoint needs to be refactored a bit, but it's fairly minor and this endpoint may be useful for now for working on frontend integration.

@wittejm wittejm merged commit 06c254a into codeforpdx:master Sep 8, 2019
KentShikama pushed a commit that referenced this pull request Mar 20, 2020
* added users get endpoint, with required new database operation, and tests for both
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.

4 participants