Tigers - Mica + Reyna Solar System API Parts 1 + 2#31
Open
reynamdiaz wants to merge 23 commits intoAda-C18:mainfrom
Open
Tigers - Mica + Reyna Solar System API Parts 1 + 2#31reynamdiaz wants to merge 23 commits intoAda-C18:mainfrom
reynamdiaz wants to merge 23 commits intoAda-C18:mainfrom
Conversation
endpoint for returning single planet
create a planet
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Nic ework Reyna & Mica, you did really well here. I particularly like your validation work on the routes. I left a few minor comments let me know if you have questions via Slack.
Comment on lines
+10
to
+23
| @classmethod | ||
| def from_dict(cls, planet_data): | ||
| new_planet = Planet(name=planet_data["name"], | ||
| description=planet_data["description"], | ||
| moons=planet_data["moons"]) | ||
| return new_planet | ||
|
|
||
| def to_dict(self): | ||
| return { | ||
| "id": self.id, | ||
| "name": self.name, | ||
| "description": self.description, | ||
| "moons": self.moons | ||
| } No newline at end of file |
Comment on lines
+25
to
+27
| if ("name" not in request_body or "description" not in request_body | ||
| or "moons" not in request_body): | ||
| return make_response(f"Invalid Request", 400) |
There was a problem hiding this comment.
Great validation, could this be abstracted in to a helper method and used in the update action as well?
| planets_response.append(planet.to_dict()) | ||
| return jsonify(planets_response) | ||
|
|
||
| def validate_model(cls, model_id): |
Comment on lines
+82
to
+85
| planet.name = request_body["name"] | ||
| planet.description = request_body["description"] | ||
| planet.moons = request_body["moons"] | ||
|
|
| assert response.status_code == 404 | ||
| assert response_body == {"message": "Planet 6 not found"} | ||
|
|
||
| def test_create_one_planet(client): |
There was a problem hiding this comment.
You should also test an invalid create action.
Comment on lines
+77
to
+97
| def update_planet(planet_id): | ||
| planet = validate_model(Planet, planet_id) | ||
|
|
||
| request_body = request.get_json() | ||
|
|
||
| planet.name = request_body["name"] | ||
| planet.description = request_body["description"] | ||
| planet.moons = request_body["moons"] | ||
|
|
||
| db.session.commit() | ||
|
|
||
| return make_response(f"Planet #{planet.id} successfully updated") | ||
|
|
||
| @planets_bp.route("/<planet_id>", methods=["DELETE"]) | ||
| def delete_planet(planet_id): | ||
| planet = validate_model(Planet, planet_id) | ||
|
|
||
| db.session.delete(planet) | ||
| db.session.commit() | ||
|
|
||
| return make_response(f"Planet #{planet.id} successfully deleted") No newline at end of file |
There was a problem hiding this comment.
Just noting the delete and update actions are untested.
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.
Part 1 - Waves 01 + 02
Part 2 - Waves 03 - 06