Skip to content

Conversation

@CatherineBandarchuk
Copy link

No description provided.

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

Comment on lines +25 to +27
new_planet = Planet(name=planet_data["name"],
length_of_year=planet_data["length_of_year"],
description=planet_data["description"])

Choose a reason for hiding this comment

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

This is a completely valid way to break the line up, but I wanted to share another format that's common across languages. This involves dropping all the arguments to their own lines. The benefit of this is making the arguments very clear from other statements and the use of indentation to show we're inside something spanning multiple lines:

# Original code
new_planet = Planet(name=planet_data["name"],
                        length_of_year=planet_data["length_of_year"],
                        description=planet_data["description"])

# Alternate formatting
new_planet = Planet(
    name=planet_data["name"],
    length_of_year=planet_data["length_of_year"],
    description=planet_data["description"]
)

Comment on lines +21 to +26
from app.models.planet import Planet

return app
db.init_app(app)
migrate.init_app(app, db)

from app.models.planet import Planet

Choose a reason for hiding this comment

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

It looks like Planet is imported twice in this file, we can remove one of these lines.

Choose a reason for hiding this comment

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

Thank you. :) I didn't notice. Fixed it.

Comment on lines +17 to +20
moon_names = []
for moon in self.moons:
moon_names.append(moon.name)
planet_as_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_as_dict["moons"] = [moon.name for moon in self.moons]

Choose a reason for hiding this comment

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

I'm still working to be comfortable to use comprehension the same as lambda function. But I'll try to use it more often.

Comment on lines +15 to +19
# Filtering by moon name (return all records which name contains planet_name_query)
moon_name_query = request.args.get("name")

if moon_name_query:
moon_query = moon_query.filter(Moon.name.ilike(f"%{moon_name_query}%"))

Choose a reason for hiding this comment

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

Since these lines of code are tightly related, I would consider removing the blank line on line 17. This feedback applies across this function where there is a separation between getting a request argument and immediately using it.

Choose a reason for hiding this comment

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

Ok. Thank you. I used the same structure during all project, sorry.

Copy link

@kelsey-steven-ada kelsey-steven-ada Jan 11, 2023

Choose a reason for hiding this comment

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

It's all good, teams and languages may have guidelines, but there is a lot in code style that is subjective. This feedback is not a strict requirement, it is based on the principles of keeping tightly related code closer together and what reads easiest for me. A lot of these small code adjustments often come when you have time to review and refactor your code once it's working, which I know there wasn't a lot of space for with this project and retro video store.

Comment on lines +38 to +40
moon_response = []
for moon in moon_query:
moon_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.

moon_response+= [moon.to_dict() for moon in moon_query]

Choose a reason for hiding this comment

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

Nice, you're about there! We would use = since the comprehension creates the whole list we want, we don't need to append to, or extend a list that already exists.

from app.models.moon import Moon
from app.models.planet import Planet
from flask import Blueprint, jsonify, abort, make_response, request
from .validate_routes import validate_model, validate_moon_user_input, validate_planet_user_input

Choose a reason for hiding this comment

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

It looks like validate_planet_user_input is imported to this file but isn't used. We should check our imports & remove ones that aren't used.


# Validating the user input to create or update the table planet
# Returning the valid JSON if valid input
def validate_planet_user_input(planet_value):

Choose a reason for hiding this comment

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

This function is only used by planet_routes.py, as such, I'd consider placing this function in that file to keep it close to where it is used.

or planet_value["name"] == "" \
or "length_of_year" not in planet_value \
or not isinstance(planet_value["length_of_year"], int) \
or planet_value["length_of_year"] <=0 \

Choose a reason for hiding this comment

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

Reminder that we want to leave a space on either side of comparison operators.

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