-
Notifications
You must be signed in to change notification settings - Fork 36
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
cedar mac #29
base: main
Are you sure you want to change the base?
cedar mac #29
Conversation
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.
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. 🎃
@planets_bp.route("", methods=["GET", "POST"]) | ||
def handle_planets(): | ||
if request.method == "GET": | ||
name_query = request.args.get("name") |
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.
Nice work using query params
|
||
elif request.method == "POST": | ||
request_body = request.get_json() | ||
new_planet = Planet( |
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.
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
|
||
@planets_bp.route("/<planet_id>", methods=["GET", "PUT", "DELETE"]) | ||
def handle_planet(planet_id): | ||
planet = Planet.query.get_or_404(planet_id) |
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.
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.
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.
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.
No description provided.