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

cedar mac #29

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

cedar mac #29

wants to merge 17 commits into from

Conversation

mac-madison
Copy link

No description provided.

Copy link

@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. 🎃

@planets_bp.route("", methods=["GET", "POST"])
def handle_planets():
if request.method == "GET":
name_query = request.args.get("name")

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(

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)

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.

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