Conversation
app/routes.py
Outdated
| description = planet.description, | ||
| gravity = planet.gravity | ||
| )) | ||
| return jsonify(planets_result) |
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
There was a problem hiding this comment.
That is a good idea. We'll add this.Thank you Trenisha
app/routes.py
Outdated
| from flask import Blueprint, jsonify, make_response, abort | ||
|
|
||
|
|
||
| class Planet: |
app/routes.py
Outdated
| planets_result.append(dict( | ||
| id = planet.id, | ||
| name = planet.name, | ||
| description = planet.description, | ||
| gravity = planet.gravity | ||
| )) |
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,
description=self.description,
gravity=self.gravity,
)
There was a problem hiding this comment.
Yup. We should refactor it like that. Thank you for the suggestion.
app/routes.py
Outdated
| planets_bp = Blueprint("planets", __name__, url_prefix="/planets") | ||
|
|
||
| @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
…DO: complete wave 4 delete, test single planet get.
…lanets, implement description field search
|
|
||
| return app | ||
| else: | ||
| print("Testing is on") |
There was a problem hiding this comment.
Was this for testing your code? Or was this intentional so that you know if you are testing?
| from app import db | ||
|
|
||
|
|
||
| class Planet(db.Model): |
| @planets_bp.route("/teapot", methods=["GET", "POST"]) | ||
| def handle_teapot(): | ||
| return make_response("I'm a teapot!", 418) | ||
|
|
There was a problem hiding this comment.
Was this also yall testing some stuff out?
| return { | ||
| "id": planet.id, | ||
| "order_from_sun": planet.order_from_sun, | ||
| "name": planet.name, | ||
| "description": planet.description, | ||
| "gravity": planet.gravity | ||
| } |
There was a problem hiding this comment.
in your Planet class you can create an instance method to return this information. Then you can use the instance method over and over again.
| name_query = request.args.get("name") | ||
| description_query = request.args.get("description") | ||
| order_from_sun_query = request.args.get("order_from_sun") |
There was a problem hiding this comment.
I like how you all added different ways to query for the planets
| planets_response.append({ | ||
| "id": planet.id, | ||
| "order_from_sun": planet.order_from_sun, | ||
| "name": planet.name, | ||
| "description": planet.description, | ||
| "gravity": planet.gravity | ||
| }) |
There was a problem hiding this comment.
this could also be made an instance method in your Planet class.
|
|
||
|
|
||
| @pytest.fixture | ||
| def app(): |
| @@ -0,0 +1,71 @@ | |||
| # from hello-books | |||
|
|
|||
No description provided.