-
Notifications
You must be signed in to change notification settings - Fork 61
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
Sea Turtles Hope W. & Natalia W. #25
base: main
Are you sure you want to change the base?
Conversation
planets_response.append({ | ||
"id": planet.id, | ||
"name": planet.name, | ||
"moons": planet.moons, | ||
"description": planet.description | ||
}) |
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.
this could be moved to your planets class as an instance method. Then you would call that instance method here.
def make_dict(self):
return dict(
id=self.id,
name=self.name,
moons=self.moons,
description=self.description,
)
app/routes.py
Outdated
|
||
|
||
@planets_bp.route("", methods=["GET"]) | ||
def handle_planets(): |
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.
Conventionally you would see the naming of the function be similar to the CRUD operation you are performing. Like get_planets
or get_all_planets
return jsonify(planets_response) | ||
|
||
@planets_bp.route("<planet_id>", methods=["GET"]) | ||
def handle_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.
Conventionally you would see the naming of the function be similar to the CRUD operation you are performing. Like get_one_planet
or get_a_planet
"description": planet.description | ||
} | ||
|
||
def validate_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.
💃🏽💃🏽💃🏽
"moons": planet.moons, | ||
"description": planet.description | ||
}) | ||
return jsonify(planets_response) |
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.
Here its nice to add a 200 status code. Even though it happens by default it adds readability to your code.
return jsonify(planets_result), 200
@@ -0,0 +1,23 @@ | |||
from app import db | |||
|
|||
class Planet(db.Model): |
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 addition of instance methods. For your columns, would you make them nullable? Like nullable = False
.
planet.name = request_body["name"] | ||
planet.moons = request_body["moons"] | ||
planet.description = request_body["description"] |
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.
you can use your class method that you made here
from app.models.planet import Planet | ||
|
||
@pytest.fixture | ||
def app(): |
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.
looks good
@@ -0,0 +1,48 @@ | |||
def test_get_all_books_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.
tests look good!
No description provided.