Skip to content

Tigers - Pavi and Rose D18#38

Open
rose-codes wants to merge 16 commits intoAda-C18:mainfrom
rose-codes:main
Open

Tigers - Pavi and Rose D18#38
rose-codes wants to merge 16 commits intoAda-C18:mainfrom
rose-codes:main

Conversation

@rose-codes
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread app/models/planet.py
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good helper methods

Comment thread app/routes.py
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great helper function

Comment thread app/routes.py
planets_bp = Blueprint("planets", __name__, url_prefix="/planets")

@planets_bp.route("", methods=["POST"])
def create_new_planet():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to include validation on the request body for this post request. Basically check to ensure that the required fields are present.

Comment thread app/routes.py
return make_response(f"Planet {new_planet.name} successfully created", 201)

@planets_bp.route("", methods=["GET"])
def read_all_planets():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the query params.

Comment thread tests/test_routes.py
@@ -0,0 +1,42 @@
def test_get_all_planets_with_no_records(client):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also include a get_all _planets test with several planets in the DB as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants