Open
Conversation
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Pavi & Rose, what you have here is pretty good. It's clear you didn't have time to finish, but I left some comments and suggestions which may help with future APIs.
Comment on lines
+10
to
+23
| def to_dict(self): | ||
| planet_to_dict = {} | ||
| planet_to_dict["id"] = self.id | ||
| planet_to_dict["name"] = self.name | ||
| planet_to_dict["description"] = self.description | ||
| planet_to_dict["moons"] = self.moons | ||
|
|
||
| return planet_to_dict | ||
|
|
||
| @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 | ||
|
|
Comment on lines
+5
to
+17
| def validate_model(cls, model_id): | ||
| try: | ||
| model_id = int(model_id) | ||
| except: | ||
| abort(make_response({"message":f"{cls.__name__} {model_id} invalid"}, 400)) | ||
|
|
||
| model = cls.query.get(model_id) | ||
|
|
||
| if not model: | ||
| abort(make_response({"message":f"{cls.__name__} {model_id} not found"}, 404)) | ||
|
|
||
| return model | ||
|
|
| planets_bp = Blueprint("planets", __name__, url_prefix="/planets") | ||
|
|
||
| @planets_bp.route("", methods=["POST"]) | ||
| def create_new_planet(): |
There was a problem hiding this comment.
You may want to include validation on the request body for this post request. Basically check to ensure that the required fields are present.
| return make_response(f"Planet {new_planet.name} successfully created", 201) | ||
|
|
||
| @planets_bp.route("", methods=["GET"]) | ||
| def read_all_planets(): |
| @@ -0,0 +1,42 @@ | |||
| def test_get_all_planets_with_no_records(client): | |||
There was a problem hiding this comment.
I would also include a get_all _planets test with several planets in the DB as well.
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.