Skip to content

cedar mac#29

Open
mac-madison wants to merge 17 commits intoAda-C16:mainfrom
mac-madison:main
Open

cedar mac#29
mac-madison wants to merge 17 commits intoAda-C16:mainfrom
mac-madison:main

Conversation

@mac-madison
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

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

Great work on your first Flask project. Your code is clear and readable, and you have successfully implemented all the features. I've left a few comments to consider for the next project on how to handle invalid user input. Please let me know if you have any questions. 🎃

Comment thread app/routes.py
@planets_bp.route("", methods=["GET", "POST"])
def handle_planets():
if request.method == "GET":
name_query = request.args.get("name")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work using query params

Comment thread app/routes.py

elif request.method == "POST":
request_body = request.get_json()
new_planet = Planet(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider how this code would behave if "name" or "description" were missing from the request body. One way to handle this sort of invalid request body is with the following code:

if "name" not in request_body or "description" not in request_body":
    return {"error":"incomplete request body", 400

Comment thread app/routes.py

@planets_bp.route("/<planet_id>", methods=["GET", "PUT", "DELETE"])
def handle_planet(planet_id):
planet = Planet.query.get_or_404(planet_id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of get_or_404. If you were to separate out handle_planet into different functions for each verb, consider how you could move this functionality into a helper function.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider also how this method would behave if planet_id was not an integer. How can we build in error checking for the parameters in the route.

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