-
Notifications
You must be signed in to change notification settings - Fork 20
Sphinx-Denise and Olga #16
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! The project is correctly organized and your model and routes look good. Let me know if you have questions about my comments.
app/models/planet.py
Outdated
self.id = id | ||
self.name = name | ||
self.description = 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.
How would you write the to_dict
instance method so you can take an instance of Planet and turn it into a dictionary that will be returned as a response to a client's request?
app/routes/planet_routes.py
Outdated
for planet in planets: | ||
if planet.id == int(planet_id): | ||
return { | ||
"id": planet.id, | ||
"name": planet.name, | ||
"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.
After your model has been validated, we don't need to loop through all the planets again to see if the id matches. Have a look at the validate_planet
function and see that you already check to see if the id matches on line 40-42.
for planet in planets: | |
if planet.id == int(planet_id): | |
return { | |
"id": planet.id, | |
"name": planet.name, | |
"description": planet.description, | |
} | |
return { | |
"id": planet.id, | |
"name": planet.name, | |
"description": planet.description, | |
} |
app/routes/planet_routes.py
Outdated
# @planets_bp.post("") | ||
# def create_planet(): | ||
# request_body = request.get_json() | ||
# title = request_body["title"] | ||
# description = request_body["description"] | ||
|
||
# new_book = Planet(title=title, description=description) | ||
# db.session.add(new_planet) | ||
# db.session.commit() | ||
|
||
# response = { | ||
# "id": new_planet.id, | ||
# "title": new_planet.name, | ||
# "description": new_planet.description, | ||
# } | ||
# return response, 201 |
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.
We'll have a look at how the model needs to be updated in order for the POST route to work!
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 on part 2 of solar-system!
{ | ||
"id": planet.id, | ||
"name": planet.name, | ||
"description": planet.description, | ||
"diameter": planet.diameter | ||
} |
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.
Prefer your Planet model has a to_dict method so that it can be called in your different routes instead repeating code. It would also help your routes be more concise.
response = { | ||
|
||
"id": new_planet.id, | ||
"name": new_planet.name, | ||
"description": new_planet.description, | ||
"diameter": new_planet.diameter | ||
} |
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.
Could call to_dict
here too
return { | ||
|
||
"id": planet.id, | ||
"name": planet.name, | ||
"description": planet.description, | ||
"diameter": planet.diameter | ||
} |
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.
Could call to_dict
on planet here instead so creating this literal dictionary isn't happening three different times in your route file.
tests/conftest.py
Outdated
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/test_planet_routes.py
Outdated
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.
👍
test_fixtures.py
Outdated
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.
Is this file just for practice? I'm not clear on what it's testing and it's not inside your test directory.
No description provided.