-
Notifications
You must be signed in to change notification settings - Fork 79
Marie and Luciane #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Marie & Luciane, this looks good. I made some minor suggestions, let me know if you have any questions via slack.
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the helper methods
@@ -0,0 +1,23 @@ | |||
from app import db |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great helper
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing some validation on the request body to ensure required fields are present would be nice.
planet.name = request_body["name"] | ||
planet.description = request_body["description"] | ||
planet.size = request_body["size"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting this route is untested
return make_response(jsonify(f"Planet #{planet.id} successfully updated")) | ||
|
||
@planets_bp.route("/<planet_id>", methods=["DELETE"]) | ||
def delete_planet(planet_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting this route is untested
No description provided.