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

Raha M.Rastagar, Jamie Horvath Sharks C17 Digital #23

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

Conversation

glassofcat
Copy link

No description provided.

Copy link

@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 on Part 1! LGTM 👍

Comment on lines +7 to +8
from .routes import planet_bp
app.register_blueprint(planet_bp)

Choose a reason for hiding this comment

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

👍

Comment on lines +4 to +16
class Planet:
def __init__(self, id, name, description, moons):
self.id = id
self.name = name
self.description = description
self.moons = moons
def to_json(self):
return {
"id": self.id,
"name": self.name,
"desciption": self.description,
"moons": self.moons
}

Choose a reason for hiding this comment

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

Nice work! This to_json() helper method will be especially helpful as we continue to make more routes.

Choose a reason for hiding this comment

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

Don't forget to add a space in between our functions to improve readability.

Comment on lines +27 to +28
Planet(9, "Pluto", "may or may not be a planet, poor Pluto", 1)
]

Choose a reason for hiding this comment

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

I disagree... Pluto is most definitely a planet! 😆

Comment on lines +32 to +36
def read_planets():
planets_response = []
for planet in planets:
planets_response.append(planet.to_json())
return jsonify(planets_response), 200

Choose a reason for hiding this comment

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

Great work! We can also use a list comprehension to write the logic for this function:

def read_planets():
    planets_response = [planet.to_json() for planet in planets]
    return jsonify(planets_response), 200

Comment on lines +38 to +48
def validate_planet(planet_id):
try:
planet_id = int(planet_id)
except:
abort(make_response({"message":f"planet {planet_id} invalid"}, 400))

for planet in planets:
if planet.id == planet_id:
return planet

abort(make_response({"message":f"planet {planet_id} not found"}, 404))

Choose a reason for hiding this comment

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

👍 Nice work! The validation for detecting a bad id and for an id with no record looks good!

Comment on lines +50 to +53
@planet_bp.route("/<planet_id>", methods=["GET"])
def read_one_planet(planet_id):
planet = validate_planet(planet_id)
return jsonify(planet.to_json(), 200)

Choose a reason for hiding this comment

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

Nice use of the helper method! This looks great!

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