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

review #5

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open

review #5

wants to merge 60 commits into from

Conversation

code-sleuth
Copy link
Owner

No description provided.

def post(self):
# Handle POST request for this view. Url ---> /auth/register"""
# Query to see if the user already exists
post_data = request.get_json(force=True)

Choose a reason for hiding this comment

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

Look into how to use reqeuest.json instead of request.get_json to help with data validation.

Copy link

Choose a reason for hiding this comment

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

It looks like request.json in deprecated in flask versions greater than 0.11
pallets/flask#1421
wtforms/flask-wtf#245

Choose a reason for hiding this comment

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

@dennisja thank you for that. Had no idea and it looks like the get functionality has been added to.get_json().

Choose a reason for hiding this comment

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

# Register new user
username = post_data['username']
fullname = post_data['fullname']
password = post_data['password']

Choose a reason for hiding this comment

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

The assignment in lines 45-47 can be handled immediately after defining post. then use the variables in all your queries.
Then it would be better to use username = request.json.get('username') and password = request.json.get('password') to avoid errors if one of the keys is missing in the request

Copy link

@valeria-chemtai valeria-chemtai Dec 3, 2017

Choose a reason for hiding this comment

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

@code-sleuth as per the concern raised by @dennisja it would be better to use username = post_data.get('username') and password = post_data.get('password') instead of extracting the data using keys.

response = {
'message': str(ex)
}
return make_response(jsonify(response)), 401

Choose a reason for hiding this comment

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

Why is this 401?

'message': 'User exists. Login'
}

return make_response(jsonify(response)), 202

Choose a reason for hiding this comment

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

Why 202?....Status code 202 means the request has been accepted.
http://www.restapitutorial.com/httpstatuscodes.html

else:
# User does not exist. Therefore, we return an error message
response = {
'message': 'Invalid username or password'

Choose a reason for hiding this comment

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

This message is confusing. It would be better to inform the user they should register first before trying to login.

recipe_blue_print.add_url_rule('/recipes/<int:id>', view_func=recipes_view_edit, methods=['DELETE', 'PUT', 'GET'])
# Define the rule for recipes url ---> /recipes/search?q=<sting:q>&limit=<int:limit>&page=<int:page>'
recipe_blue_print.add_url_rule('/recipes/search', view_func=search_by_name, methods=['GET'])

Choose a reason for hiding this comment

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

Make use of class based views i.e. MethodView makes code much cleaner.
Look into how to cover the method for /recipes/search url under the method for /recipes url

})), 200

users_blue_print.add_url_rule('/users', view_func=users, methods=['GET'])
users_blue_print.add_url_rule('/users/<int:id>', view_func=edit_by_id, methods=['DELETE', 'PUT', 'GET'])

Choose a reason for hiding this comment

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

Is this file, app/users_blue_print/views.py, necessary?


if __name__ == '__main__':
app.run()
app.run(debug=True, port=5005)

Choose a reason for hiding this comment

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

The file manage.py makes this file(main_app.py) redundant.



def downgrade():
${downgrades if downgrades else "pass"}

Choose a reason for hiding this comment

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

Delete and gitignore the migrations folder and its contents.

else:
return None


Choose a reason for hiding this comment

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

Place line 8-27 in a different file. You can look into how to make a decorator. It'll help you avoid repetition every time you access endpoints.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 73144b3 on dev into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 827b55e on dev into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 36e851f on dev into ** on master**.

@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro February 14, 2018 12:45 Inactive
@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro February 14, 2018 12:51 Inactive
@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro February 14, 2018 12:56 Inactive
@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro March 20, 2018 18:09 Inactive
@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro May 14, 2018 08:58 Inactive
@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro May 14, 2018 09:08 Inactive
@code-sleuth code-sleuth temporarily deployed to yummy-recipes-api-pro May 14, 2018 09:16 Inactive
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