Open
Conversation
"trying to resolve confilcts!"
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Misha & Leimomi. This is quite well done. I left some minor comments. Let me know if you have questions/comments via slack.
Comment on lines
+11
to
+28
| def to_dict(self): | ||
| planet_as_dict = {} | ||
| planet_as_dict["id"] = self.id | ||
| planet_as_dict["name"] = self.name | ||
| planet_as_dict["color"] = self.color | ||
| planet_as_dict["livability"] = self.livability | ||
| planet_as_dict["moons"] = self.moons | ||
| planet_as_dict["is_dwarf"] = self.is_dwarf | ||
| return planet_as_dict | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, planet_data): | ||
| new_planet = Planet(name=planet_data["name"], | ||
| color=planet_data["color"], | ||
| moons=planet_data["moons"], | ||
| livability=planet_data["livability"], | ||
| is_dwarf=planet_data["is_dwarf"]) | ||
| return new_planet No newline at end of file |
Comment on lines
+7
to
+18
| def validate_model(cls, model_id): | ||
| try: | ||
| model_id = int(model_id) | ||
| except: | ||
| abort(make_response({"message":f"the planet {cls.__name__} {model_id} is invalid, please search by planet_id."}, 400)) | ||
|
|
||
| planet = cls.query.get(model_id) | ||
|
|
||
| if not planet: | ||
| abort(make_response({"message":f"the planet {cls.__name__} {model_id} doesn't exist."}, 404)) | ||
| return planet | ||
|
|
|
|
||
| @planet_bp.route("", methods=["POST"]) | ||
| def create_new_planet(): | ||
| request_body = request.get_json() |
There was a problem hiding this comment.
Doing some validation on the request body would be appropriate.
Comment on lines
+53
to
+57
| planet.name = request_body["name"], | ||
| planet.color = request_body["color"], | ||
| planet.moons = request_body["moons"], | ||
| planet.livability = request_body["livability"], | ||
| planet.is_dwarf = request_body["is_dwarf"] |
There was a problem hiding this comment.
Doing some validation on the request body here would also be appropriate.
| @@ -0,0 +1,80 @@ | |||
| from app.models.planet import Planet | |||
|
|
|||
| assert response.status_code == 200 | ||
| assert response_body == {'id': 1, 'color': "pink", 'is_dwarf': True, 'livability': 3, 'moons': 99, 'name': "Pretend Planet X"} | ||
|
|
||
| def test_create_one_new_planet(client): |
There was a problem hiding this comment.
Also testing a create action with an invalid request body would be appropriate.
| return make_response(f"Planet #{model_id} successfully updated.") | ||
|
|
||
| @planet_bp.route("/<model_id>", methods = ["DELETE"]) | ||
| def delete_planet(model_id): |
| return make_response(f"Planet {new_planet.name} successfully created", 201) | ||
|
|
||
| @planet_bp.route("/<model_id>", methods = ["PUT"]) | ||
| def update_planet(model_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.
No description provided.