Skip to content

Conversation

@lisabethu88
Copy link

No description provided.

lisabethu88 and others added 30 commits December 14, 2022 13:56
…r by name and sort in either ascending or descending order.
… file from routes.py. Deleted routes.py. Added functionality that allows the user to sort by any column.
'to_dict_refactor' of https://github.com/lisabethu88/solar-system-api into to_dict_refactor
Copy link

@kelsey-steven-ada kelsey-steven-ada 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 Lisa & Chelsea! I've left a few comments & questions, feel free to reply here or message me on Slack if you have questions on the feedback 🙂

description = db.Column(db.String)
name = db.Column(db.String)
planet_id = db.Column(db.Integer, db.ForeignKey('planet.id'))
planets = db.relationship("Planet", back_populates = "moons")

Choose a reason for hiding this comment

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

Does this attribute hold a single planet, or many planets? If it is only ever connected to 1 planet, I would suggest using a singular variable name to better describe the contents.

Comment on lines +17 to +20
moon_names = []
for moon in self.moons:
moon_names.append(moon.name)
planet_dict["moons"] = moon_names

Choose a reason for hiding this comment

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

I know this is the way I grabbed cat names during the class livecode, but this is a great place for a list comprehension!

planet_dict["moons"] = [moon.name for moon in self.moons]

@@ -0,0 +1,32 @@
from app import db

Choose a reason for hiding this comment

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

It looks like the route files are loose in the app folder. To keep a project organized as it grows, I recommend creating a routes folder inside of app to place these in.

Comment on lines +24 to +26
moons_response = []
for moon in moons:
moons_response.append(moon.to_dict())

Choose a reason for hiding this comment

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

This would be another great place for a list comprehension - what could that look like?

Choose a reason for hiding this comment

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

moons_response = [moon.to_dict() for moon in moons]

from sqlalchemy import desc, asc


# ---------helper functions--------

Choose a reason for hiding this comment

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

Specific teams might have their own style guides, but it is a common practice to place helper functions at the end of a file rather than the beginning. An often-used analogy is to lay out code like a newspaper article. Headlines and the most important information comes first - Functions that use other functions in the file go at the top. That gets followed by the details and extra information in an article, or in our code, all the helper functions that support the higher up functions.

Comment on lines +22 to +24



Choose a reason for hiding this comment

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

Tiny best practices feedback - we typically only want a single blank line to separate functions in a file. If we have blocks of functions that do different things, then we might consider using 2 blank lines. A solid example of this are lines 37 and 38 where we have 2 blank lines separating the block of helper functions from the route functions that follow.




def validate_model(cls, model_id):

Choose a reason for hiding this comment

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

Since this function is shared and not specific to the planet routes, I would suggest moving it out of the planet_routes.py file.

Comment on lines +46 to +47
# if "name" not in request_body or "description" not in request_body or 'diameter_in_km' not in request_body:
# return make_response("Invalid Request", 400)

Choose a reason for hiding this comment

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

Gentle reminder that we want to remove commented code as part of our review and clean up steps before opening PRs.

model = cls.query.get(model_id)

if not model:
abort(make_response(jsonify({"message":f"{cls.__name__} #{model_id} not found"}), 404))

Choose a reason for hiding this comment

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

Around best practices, there are many lines across the files that break the PEP 8 guide of 79 characters max per line. I would keep an eye out for this in the future, especially on lines where there are nested function calls.

return app.test_client()

@pytest.fixture
def one_planet(app):

Choose a reason for hiding this comment

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

I suggest updating this name to reflect that the function also creates a moon.

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