Open
Conversation
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Selam & Kinda. You hit the learning goals here. Well done. I left some minor comments and let me know if you have questions via slack.
Comment on lines
+10
to
+24
| def to_dict(self): | ||
| planet_dict = {} | ||
| planet_dict["id"] = self.id | ||
| planet_dict["name"] = self.name | ||
| planet_dict["description"] = self.description | ||
| planet_dict["diameter"] = self.diameter | ||
| return planet_dict | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, planet_data): | ||
| new_planet = Planet(name=planet_data["name"], | ||
| description=planet_data["description"], | ||
| diameter=planet_data["diameter"] | ||
| ) | ||
| return new_planet No newline at end of file |
Comment on lines
+11
to
+22
| def validate_planet(cls, planet_id): | ||
| try: | ||
| planet_id = int(planet_id) | ||
| except: | ||
| abort(make_response({"message":f"{cls.__name__} {planet_id} invalid"}, 400)) | ||
|
|
||
| planet = cls.query.get(planet_id) | ||
|
|
||
| if not planet: | ||
| abort(make_response({"message":f"{cls.__name__} {planet_id} not found"}, 404)) | ||
|
|
||
| return planet |
|
|
||
| @planet_bp.route("", methods=["POST"]) | ||
| def create_planet(): | ||
| request_body = request.get_json() |
There was a problem hiding this comment.
Doing some validation on the request body (to make sure it has the required fields) would be appropriate.
| def update_planet(planet_id): | ||
| planet = validate_planet(Planet, planet_id) | ||
|
|
||
| request_body = request.get_json() |
There was a problem hiding this comment.
Doing validation on the request body would be appropriate here.
| } | ||
| ] | ||
|
|
||
| def test_create_one_planet(client): |
There was a problem hiding this comment.
Testing the create action with an invalid request body is also appropriate.
| return planet.to_dict() | ||
|
|
||
| @planet_bp.route("/<planet_id>", methods=["DELETE"]) | ||
| def delete_planet(planet_id): |
| return make_response(jsonify(f"Planet #{planet.id} successfully deleted!")) | ||
|
|
||
| @planet_bp.route("/<planet_id>", methods=["PUT"]) | ||
| def update_planet(planet_id): |
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.
Waves 1 & 2