Skip to content

Vange Cabebe Spruce c16#30

Open
cabebe-bloop wants to merge 9 commits intoAda-C16:mainfrom
cabebe-bloop:main
Open

Vange Cabebe Spruce c16#30
cabebe-bloop wants to merge 9 commits intoAda-C16:mainfrom
cabebe-bloop:main

Conversation

@cabebe-bloop
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@audreyandoy audreyandoy 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 Vange and Cabebe! Overall, the code looks great. My primary feedback involves utilizing helper methods and the single responsibility principle.

Comment thread app/__init__.py
db.init_app(app)
migrate.init_app(app, db)

from app.models.planet import 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.

The blueprints import the models so we don't actually need the model import anymore.

Comment thread app/models/planet.py
name = db.Column(db.String)
description = db.Column(db.String)
sign = db.Column(db.String)

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 adding a helper function to turn instances into a dictionary

Comment thread app/routes.py
Comment on lines +13 to +18
planets_response.append({
"id": planet.id,
"name": planet.name,
"description": planet.description,
"sign": planet.sign
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

*See comment about helper function to turn instances into dictionaries. We could refactor this line from 5 lines to one by using a helper function

Suggested change
planets_response.append({
"id": planet.id,
"name": planet.name,
"description": planet.description,
"sign": planet.sign
})
planets_response.append({planet.to_dict()})

Comment thread app/routes.py
Comment on lines +19 to +20
if not planets_response:
return jsonify("There are no planets yet! :O", 200)
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 custom check for empty lists

Comment thread app/routes.py
db.session.add(new_planet)
db.session.commit()

return f"Planet {new_planet.name} created.", 201
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't forget to jsonify your responses

Suggested change
return f"Planet {new_planet.name} created.", 201
return jsonify(f"Planet {new_planet.name} created."), 201

Comment thread app/routes.py
return f"Planet {new_planet.name} created.", 201


@planets_bp.route("/<planet_id>", methods = ["GET", "PUT", "DELETE"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

see comment on get/post request about putting each request method into separate functions

Comment thread app/routes.py
Comment on lines +66 to +67
return jsonify(f"Planet {planet.name} successfully deleted! bye bitch")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤣 this delete message

Comment thread app/routes.py
Comment on lines +46 to +50
return {
"name": planet.name,
"description": planet.description,
"sign": planet.sign
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

to_dict() helper method would have been nice here as well :P

Comment thread tests/test_routes.py
Comment on lines +17 to +20
assert response_body == {
"description": "way out there",
"name": "pluto",
"sign": "Scorpio"}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't forget to display the id in the response as well

Comment thread tests/conftest.py
Comment on lines +27 to +33
def add_three_planets():
pluto = Planet(name="pluto", description="way out there", sign="Scorpio")
mercury = Planet(name="mercury", description="messenger closest to sign", sign="Virgo")
saturn = Planet(name="saturn", description="forever hula hooping", sign="Capricorn")

db.session.add_all([pluto, mercury, saturn])
db.session.commit() No newline at end of file
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 returning [pluto, mercury, saturn ] after this line, so that tests can make use of the ids of the records, and anything else that's part of the record that might be useful in the test.

Comment thread app/routes.py
Comment on lines +7 to +8
@planets_bp.route("", methods = ["GET", "POST"])
def get_planets():
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 separating each request method into its different functions. This makes testing the endpoints much easier to do.

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.

3 participants