Raha M.Rastagar, Jamie Horvath Sharks C17 Digital#23
Open
glassofcat wants to merge 4 commits intoada-c17:mainfrom
Open
Raha M.Rastagar, Jamie Horvath Sharks C17 Digital#23glassofcat wants to merge 4 commits intoada-c17:mainfrom
glassofcat wants to merge 4 commits intoada-c17:mainfrom
Conversation
audreyandoy
reviewed
Apr 28, 2022
Comment on lines
+7
to
+8
| from .routes import planet_bp | ||
| app.register_blueprint(planet_bp) |
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 | ||
| } |
There was a problem hiding this comment.
Nice work! This to_json() helper method will be especially helpful as we continue to make more routes.
There was a problem hiding this comment.
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) | ||
| ] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
👍 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) No newline at end of file |
There was a problem hiding this comment.
Nice use of the helper method! This looks great!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.