Open
Conversation
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Marie & Luciane, this looks good. I made some minor suggestions, let me know if you have any questions via slack.
Comment on lines
+9
to
+24
| def to_dict(self): | ||
| planet_as_dict = {} | ||
| planet_as_dict["id"] = self.id | ||
| planet_as_dict["name"] = self.name | ||
| planet_as_dict["description"] = self.description | ||
| planet_as_dict["size"] = self.size | ||
|
|
||
| return planet_as_dict | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, planet_data): | ||
| new_planet = Planet(name=planet_data["name"], | ||
| description=planet_data["description"], | ||
| size=planet_data["size"]) | ||
| return new_planet | ||
|
|
| @@ -0,0 +1,23 @@ | |||
| from app import db | |||
There was a problem hiding this comment.
Just noticed you have an app/model/planet.py and app/models/planet.py So.... one isn't needed.
| planets_bp = Blueprint("planets", __name__, url_prefix="/planets") | ||
|
|
||
| #helper functions | ||
| def validate_model(cls, model_id): |
| @planets_bp.route("", methods=["POST"]) | ||
| def create_planet(): | ||
| request_body = request.get_json() | ||
| new_planet = Planet.from_dict(request_body) |
There was a problem hiding this comment.
Doing some validation on the request body to ensure required fields are present would be nice.
Comment on lines
+56
to
+58
| planet.name = request_body["name"] | ||
| planet.description = request_body["description"] | ||
| planet.size = request_body["size"] |
There was a problem hiding this comment.
Again some validation in the request body would be nice.
| @@ -0,0 +1,47 @@ | |||
| # get all planets and return no records | |||
| def test_get_all_planets_with_no_records(client): | |||
There was a problem hiding this comment.
Doing a get all with multiple planets would make a good test.
| "size": "Big" | ||
| } | ||
|
|
||
| def test_create_one_planet(client): |
There was a problem hiding this comment.
Testing an invalid create action would make a good test as well.
| return planet.to_dict() | ||
|
|
||
| @planets_bp.route("/<planet_id>", methods=["PUT"]) | ||
| def update_planet(planet_id): |
| return make_response(jsonify(f"Planet #{planet.id} successfully updated")) | ||
|
|
||
| @planets_bp.route("/<planet_id>", methods=["DELETE"]) | ||
| def delete_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.
No description provided.