Sea Turtles Hope W. & Natalia W.#25
Conversation
| planets_response.append({ | ||
| "id": planet.id, | ||
| "name": planet.name, | ||
| "moons": planet.moons, | ||
| "description": planet.description | ||
| }) |
There was a problem hiding this comment.
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.
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.
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): |
| "moons": planet.moons, | ||
| "description": planet.description | ||
| }) | ||
| return jsonify(planets_response) |
There was a problem hiding this comment.
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.
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.
you can use your class method that you made here
| from app.models.planet import Planet | ||
|
|
||
| @pytest.fixture | ||
| def app(): |
| @@ -0,0 +1,48 @@ | |||
| def test_get_all_books_with_no_records(client): | |||
No description provided.